The eight-time champion was two sets up and had a match point in the third, but nearly 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.
He saved a match point at 4-5 when Federer missed a forehand, then broke to serve for the third set.
The top-seeded Federer did not lose a set at Wimbledon last year, and won his first 14 sets this year - tying his tournament record of 34 consecutive set wins - before losing three in a row to Anderson.
Two-time champion Nadal is through to the last eight at Wimbledon for the first time since 2011.
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. I'm glad that we're talking tonight after a fourth-round win.' Djokovic then made an admission: 'I think I've in a way earned the right to play quarter-finals on Centre Court, we've put the request with the organizers.
Anderson is the first South African man in the Wimbledon last-eight since Wayne Ferreira in 1994.
The other quarter-final features American John Isner and Canadian former runner-up Milos Raonic.
Roger Federer was a point away from a rather tidy, straight-set victory in the Wimbledon quarterfinals.
Mannarino was already handed a point after Federer's shot landed outside the court, but the Swiss was seen going on his front-foot and defending the ball with the middle of his racquet and a ideal roll of the wrists.
Djokovic has had a hard two years but is beginning to look and feel a lot more like his old self again. His last semifinal appearance at a Grand Slam was at the US Open in 2016, where he lost in the final to Stan Wawrinka.
"I think I had chances, I'm not sure exactly how many".
However since then, the 2.03m-tall Anderson has improved markedly and Wednesday's match will be their first meeting on grass. "I was in the flow of the match", eighth seed Anderson said.
Anderson continued to grow in confidence and stature as the match wore on, holding his nerve to earn his first win over Federer in five attempts.
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.
While England will be gearing up for its biggest match of the day - the World Cup semi-final involving the Three Lions and Croatia, London will play host to some exciting quarter-final action of Wimbledon 2018.