Defending champion Federer had looked in complete control, but Anderson produced a stunning comeback to prevail 2-6 6-7 7-5 6-4 13-11 in four hours and 14 minutes.
Federer broke Anderson's serve in the opening game of the match, and it appeared to set the tone for the legendary Swiss to book another appearance in the last four at SW19.
However, Anderson gradually found his feet in the contest and broke serve at the end of the third and fourth sets to take Federer the distance, with the 36-year-old having recorded 14 straight sets before dropping the third.
Both players dominated behind their serve in the decider but while Federer failed to take his one opportunity, Anderson took his chance at the first time of asking to give himself an opening on his own delivery.
Federer took the first point of the 24th game but Anderson reeled off four of his own as the South African earned just a third appearance in the semi-finals of a Grand Slam.