Anderson achieved something only Jo-Wilfried Tsonga and Novak Djokovic had done before as he fought back to prevail 2-6 6-7 (5-7) 7-5 6-4 13-11 in an epic that lasted four hours and 13 minutes.
Federer had not dropped a set in his serene run through to the last eight at the All England Club, and the defending champion appeared poised for a relatively routine win when he went match point up in the third set.
The big-serving and obdurate Anderson was undaunted by the situation, staying alive before turning the tide in his favour, preventing Federer from breaking his own record for consecutive sets won at SW19.
The previously unlikely prospect of Anderson completing an unbelievable recovery appeared a more realistic possibility when he ensured the increasingly frustrated eight-time champion would have to go the distance to reach the last four.
Neither player's defences looked penetrable in a tense and absorbing fifth and for the most part there was little sign of the stalemate ending.
However, it was Federer who was stunningly the first to falter and Anderson took advantage to book a semi-final clash with either John Isner or Milos Raonic.