The Swiss eight-times champion and top seed was beaten 2-6 6-7(5) 7-5 6-4 13-11 by eighth-seeded Anderson before a stunned crowd packed into a tension-filled No. 1 Court.
It was his first win against Federer at the fifth attempt and means he is the first player representing South Africa to reach the semi-final here since Kevin Curren in 1983.
Eighth-seed Anderson, 32, saved a match point in the 10th game of the third set and grew in confidence against an increasingly-ragged Federer who had won the first set in 26 minutes.
He won the third set to snap Federer’s 34-set winning streak at Wimbledon and Federer was clearly shaken as Anderson dominated the fourth set to drag the 20-times Grand Slam champion into a decider.
Six times Anderson was required to hold serve to stay alive and each time he was equal to the task.