Despite being a three-time champion, Djokovic has featured just once on Centre Court - against British home favourite Kyle Edmund in the last 32 - in the opening four rounds.
It was Federer who faltered at 11-11, double-faulting to hand Anderson a break point which he converted when the defending champion's tired forehand smacked the net.
It is the second time that 20-times Grand Slam champion Federer has lost at Wimbledon from two sets ahead, suffering the same fate against Jo-Wilfried Tsonga in the 2011 quarter-finals.
Big-serving Anderson had never reached the final eight at the All England Club nor had he beaten Gael Monfils, but after a gruelling 7-6 (4), 7-6 (2), 5-7, 7-6 (4) triumph over the Frenchman in the fourth round, he can now tick both off his list.
Federer had been pursuing a 13th Wimbledon semi-final and a 44th appearance in the last four of a grand slam.
The only other times he has surrendered a two-set lead came against Lleyton Hewitt in Switzerland's 2003 Davis Cup semi-final loss to Australia in Melbourne, to David Nalbandian in the 2005 Masters Cup decider. "I don't think it's fair but it is what it is".
Federer squandered his match point at 5-4 on Anderson's serve in the third set but it seemed like it would only be a matter of time before he moved into the semifinals for the 13th time.
There was little sign of the drama which unfolded when Federer raced through the first set in 26 minutes.
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. This is Djokovic's second consecutive Wimbledon quarterfinal.
Anderson will play 2016 runner-up Milos Raonic of Canada or American ninth seed John Isner tomorrow for a place in Sunday's final.
"It was quite a odd feeling for me not to be able to deliver my game that I know I possess, that I know I've been delivering for so many years", Djokovic said ahead of Wednesday's quarter-finals.
He broke to 30 and then served out for a dramatic victory, having saved one match point in the third set.
After beating Monfils in a tight four-set battle, Anderson said he was exhausted after playing for three hours and 29 minutes.
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.