With Nishikori serving to stay in the match, Djokovic wrapped things up after two and a half hours on centre court on the first match point.
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.
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.
Federer had a match point in the third set at 4-5, 30-40 but failed to take it, before Anderson broke in the following game to earn the opportunity to serve out the set. Federer's tweener against Djokovic in the 2009 US Open final remains an iconic shot.
Djokovic had four break points in the first two service games alone and suffered a Wimbledon meltdown as he bounced his racket off the ground, argued with the umpire, and then went on to lose the second set.
Novak Djokovic accused a Spanish match official of "double standards".
The 12-time major victor prevailed despite picking up two code violations and accusing umpire Carlos Ramos of "double standards".
Political tensions have existed between the neighboring countries dating back to the break-up of Yugoslavia, so the 12-time Grand Slam winner's comments were met with angry posts on social media from the Serbian government official. "I've been building in the last couple of weeks and my level of tennis is going up", he said.
"I feel like I'm peaking at the right moment".
Djokovic copped a code violation for unsportsmanlike conduct after flinging his racquet into the grass behind the baseline in frustration early in the third set.
He then let rip at Ramos for failing to sanction Nishikori for a similar act in the fourth set.
"To be honest, I thought it was unnecessary to get a warning".
"I didn't harm the grass, I know how I threw the racket".
"I think it's not fair, but it is the way it is in the midst of the emotions of a match".