Federer won the first two sets, 6-2, 7-6 (5) before Anderson rallied to win the next two sets, 7-5, 6-4, becoming the first player at Wimbledon this year to take a set from Federer.
Having saved Federer's only break point of a 90-minute fifth set at 3-4, Anderson took his first chance at 11-11 and then served out for victory.
The bi-serving, 32-year-old old Anderson seemed undaunted by the pressure of the occasion and went on to win the fourth set 6-4, thanks to a solitary break in the seventh game, to tie things up and force a fifth deciding set.
Djokovic has got his wish as he will take on the world number 24 Kei Nishikori on Centre Court, while Federer will take on Anderson on court number one. Against Anderson, though he hit 16 aces, it was down to 79 %. Is it missing match points?
In a nail-biting four hour and 13 minute classic, it was 36-year-old Federer's earliest exit at the All England Club since his shock second round defeat against Sergiy Stakhovsky in 2013.
Nishikori, who had won only two matches in 15 meetings with the 12-time major victor, broke for 1-0 in the fourth but was broken straight back. He kept telling himself, "Today was going to be my day".
The only other times that Federer has surrendered a two-set lead came against Lleyton Hewitt in Switzerland's 2003 Davis Cup semifinal loss to Australia in Melbourne, to David Nalbandian in the 2005 Masters Cup decider and to Jo-Wilfried Tsonga and Novak Djokovic at consecutive slams at Wimbledon and the US Open in 2011.
But the three-time champion here turned the tables on Nishikori, holding his serve and then breaking in the next game to start a run of four successive games which allowed him to take the third set 6-2. "I was in the flow of the match", eighth seed Anderson said. Federer raced to a two-set lead but Djokovic forced a fifth before running out of steam, both physically and mentally.
China Shares Drop, Yuan Falters on New U.S. Tariff Threats
That prompted fears Beijing might go beyond matching USA import tax increases by harassing American companies in China . China has vowed to retaliate dollar-for-dollar to any further US tariffs.
He can produce huge pace from the baseline as well, and he ultimately needed a combination of skills and a great deal of mental strength to reach his first Wimbledon semifinal.
Ever since then, Anderson has been improving his game with every passing tournament.
"I think the first warning was unnecessary", said Djokovic, who was sanctioned in the second set for spearing his racquet into the court.
Federer was completely out of sorts by now and his uncharacteristic struggles on his forehand didn't improve in the fourth set.
It means Nadal is now in his 35th Grand Slam quarterfinal and following previous years of injuries and bad luck at SW19, the Spaniard was pleased to reach the last eight.
"I don't think it really mattered, to be honest", he said.
"I like the level of tennis that I'm playing on right now. I hope I can get a chance to fight for a trophy".