Federer had a match point at 5-4 in the third set, but Kevin Anderson-the 6-foot-8 ball smasher from South Africa-saved that break point and went on to win the set.
The three-time Wimbledon champion was broken in the opening game of the fourth set, but won the next four games and broke again to clinch victory.
Nadal faces the victor of Juan Martin del Potro and Gilles Simon while Federer takes on US Open finalist Kevin Anderson in the quarterfinals.
"Down 2-0 I tried my best to keep fighting and was able to scrape through and by the end I thought I did a great job. I've been building in the last couple of weeks and my level of tennis is going up", he said. You need that mindset against Roger.
"I'm ecstatic. That's what you work so hard for. Matches likes that are very special".
Nadal hasn't made the Wimbledon quarterfinals since his finals appearance in 2011.
Federer seemed to be heading for a routine victory with match point to complete a straights set win in the third.More news: Kevin Anderson didn't know he would face Roger Federer at Wimbledon
The World Cup showpiece will take place on Sunday at 18:00 (local time), which is 16:00 BST, meaning it is likely to kick off during the men's grass-court final, which eight-time champion Federer is a heavy favourite to be a part of.
Anderson had failed to take a single set off Federer in their previous four meetings.
Djokovic secured that game with a forehand victor, then saved two game points on Nishikori's serve before converting his first match point with a forehand down the line.
The Swiss lost the set in a flurry of aces, with Anderson's relentless, powerful serve sending the match into a decider.
This is Djokovic's second consecutive Wimbledon quarterfinal.
It marks the best women's doubles showing at a Grand Slam for the 26-year-old Dabrowski, who advanced to the quarter-finals with Xu at the 2017 U.S. Open and 2018 Australian Open.
Nishikori, playing in his first quarter-final at the All England Club, was bidding to become the first Japanese man to make the Wimbledon semi-finals in 85 years.More news: European Space Agency Taps Airbus for Mars Sample Return Mission
Interviewed by Sky Sport, the eight-time champion Andre Agassi himself admitted that he would like to see the epic clash: 'This would be for the history books, for everybody.
Normal service was resumed for a while at least as Federer held to love before immediately breaking back and taking the ensuing tie-break.
He was leading by two sets and 5-4 in the third when, with Anderson serving, he got to Ad-Out.
He then let rip at Ramos for failing to sanction Nishikori for a similar act in the fourth set. Every set won by Anderson required an extra game to determine the victor. "Making the semis, beating Roger Federer is something special, something I will remember", Anderson said.
The two players then held their serves brilliantly in the fifth and decisive set, until Anderson broke Federer in the 23rd game to go up 12-11.
For more sports coverage, visit the ABS-CBN Sports website.More news: Klopp defends Karius after latest Liverpool blunder
- Kepler Spacecraft’s Fuel Tank is Running Very Low
- England - World Cup - 12 July 2018
- Russell Knox uses incredible clutch putting to win Irish Open in playoff
- Cardi B has given birth and her child's name is absolutely BONKERS
- England nowhere near their potential, says manager Gareth Southgate
- Officer off beat after dispute over Puerto Rican shirt
- England handed boost as Croatia rule out Vrsaljko
- Turkey's new finance chief, Erdogan's son-in-law, vows to bring inflation down
- Trump administration threatens tariffs on another $200 billion in Chinese imports
- Instagram Model Katarina Zarutskie Savaged by Shark During Bahamas Vacation