The defending champion was two sets up and had a match point in the third, but almost three hours later he trudged off on the end of a seismic 2-6 6-7 (5/7) 7-5 6-4 13-11 upset.
Federer, 36, said: “Of course the goal is to come back here next year. I wouldn’t call it ‘unfinished business’. I felt like I did some good business here in the past already.
“So I’m all right. I’m just disappointed now.”
Federer was given a rare outing on Court One having been switched from his usual Centre Court domain for the first time in three years.
But he found himself in even more unfamiliar territory with an inspired Anderson’s relentless, thudding serve eventually overpowering the 20-time grand slam winner.
The final set lasted 90 minutes, and it was captivating. Federer eked out a break point at 4-3, Anderson quickly snuffed it out, then Anderson served to stay in the match, and did so to love.
On they went, both holding to love for 10-10, but at 11-11 it was Federer who blinked, a double fault handing South African Anderson a rare break point which he converted.
Anderson needed four more booming serves to reach a first Wimbledon semi-final, and he found them to deny Federer a 13th Wimbledon semi-final appearance.
“It’s just not one of my best days, but they don’t happen very often,” added Federer.
“It’s one of those average days you have to try to win the match, and I just couldn’t get it done today. So it’s disappointing.
“There’s nothing really that shocked me because I’ve seen Kevin play many, many times in the past.
“Even if the matches have been maybe sometimes one-sided – I didn’t lose sets against him – you always know he can pick it up, and all of a sudden you won’t see breaks for some time.
“I was very happy that I got off to the right start of the match, was able to take control somewhat of the game. I just don’t know exactly how I couldn’t create more opportunities once the third set came around.
“I think I had chances, I’m not sure exactly how many. But then fourth and fifth, obviously the fifth was long, that’s like two sets, the fifth.
“I think I had my chances, so it’s disappointing. No doubt about it.”
He added: “To be honest, I didn’t feel mental fatigue. Now I feel horribly fatigued and just awful. It’s just terrible. But that’s how it goes. Credit to him.”
Anderson next plays John Isner who reached his first grand slam semi-final by beating Milos Raonic 6-7 (5/7) 7-6 (9/7) 6-4 6-3.
Novak Djokovic beat Kei Nishikori 6-3 3-6 6-2 6-2 to move a step closer to a fourth title.
The Serbian reached his first grand slam semi-final since the US Open in 2016 with a battling performance reminiscent of days gone by, even if he did fall out with umpire Carlos Ramos. Djokovic, seeded 12th, incurred a warning for throwing his racket and was clearly frustrated, complaining of “double standards” when Nishikori was not punished for a racket throw.
He said: “I just asked the chair umpire how did I deserve that warning? I just asked him whether he thought honestly that I damaged the court with the racket. He said he thinks it damaged the court.
“Nishikori did the same in the fourth set and he didn’t get a warning. I think that’s not fair.
“He claims that he didn’t see what Nishikori has done, but apparently he always sees what I do.”
Rafael Nadal fought back from two sets to one down to defeat Juan Martin del Potro in a superb match and set up a semi-final against Djokovic.
When Del Potro sent a forehand rifling down the line to take the third set, it seemed Nadal might be following Roger Federer out of the tournament, but the world No 1 recovered superbly to triumph 7-5 6-7 (7/9) 4-6 6-4 6-4 and keep alive his hopes of an 18th grand slam title.
Nadal should have led by two sets to love but was forced to come from behind before withstanding a supreme effort from his opponent in the fifth to clinch victory after four hours and 47 minutes.
Britain’s Heather Watson and partner Tatjana Maria of Germany are out of the women’s doubles after losing 3-6 7-6 (7/5) 6-4 to Czech third seeds Katerina Siniakova and Barbora Krejcikova in the quarter-finals.
Jamie Murray remained on course to defend his mixed doubles title with new partner Victoria Azarenka with a 7-6 (8/6) 6-3 win over Matwe Middelkoop and Johanna Larsson.