It was only the third time in Federer's career that he lost a Grand Slam match after winning the first two sets.
A Federer double fault at 11-11 in the fifth opened up the door to the lone break of the decider and Anderson closed it out with a massive serve to reach a first Wimbledon semifinal.
Anderson's reward for his famous victory is a semifinal on Friday (Saturday NZT) against either American ninth seed John Isner or Canadian 13th seed Milos Raonic. Anderson, the eighth-seed, who hadn't taken a set off Federer in four previous meetings, struck again in the seventh game of the fourth set when the Swiss' forehand found the net.
The Centre Court spectators, who included the Duchess of Cornwall, Rory McIlroy and Sir Richard Branson watching on from the Royal Box, were wowed by two highlight-reel rallies in the first five games.
"Sometimes you don't feel good, and you try your best".
Vanquished champion Roger Federer plans on returning for another tilt at Wimbledon glory next year - but don't call it unfinished business. It's just different. I think this gives Anderson a better chance.
He said: 'I felt like in the last month and a half, the level of tennis has been very close to where I would like it to be, where I'm used to having it.
'I'm pleased I'll be staying there right now'.More news: Croatians who have made their mark in England
Already the owner of the most Wimbledon titles-eight-in history, Federer is playing like he's going to add another to his resume.
Boris Becker said Anderson had played the "game of his life" and, to many, will be known as the man who ended Federer's run. "And I just couldn't get it done today so it's disappointing".
The two traded winning the first 22 games in the fifth set, before Anderson broke Federer's serve and took a 12-11 lead in a match that exceeded four hours.
Nishikori, playing in his first quarterfinal at the All England Club, was bidding to become the first Japanese man to make the Wimbledon semifinals in 85 years.
"I felt good actually". He won only 3 of 12 break points on Anderson's serve in the match.
Nadal reached the quarterfinals of Wimbledon for the first time since 2011 after defeating Jiri Vesely in a 6-3, 6-3, 7-5 victory on Monday. And Nadal is almost five years younger than Federer.
"He claims that he didn't see what Nishikori has done, but apparently he always sees what I do", Djokovic said afterward, "something that I don't think is fair". "As of right now, I'm sort of more focused on that than getting too excited about the overall picture". It set Federer off - he remained heated by the overturn ("That one cost me the match, eventually", Federer said later) and he began jawing at the chair umpire to complain about a number of things, including how long Del Potro was taking to challenge. I had my chances and blew them.
DJOKOVIC THROUGH Novak Djokovic, the three-time champion, showed Centre Court's capacity crowd a fair reflection of the player he was two summers ago.