His record of 34 straight Wimbledon wins when up 2-0 was snapped in the third set, and Federer fell shortly after.
Federer had a match point at 5-4 in the third set, but struck a backhand into the net before the eighth-seeded Anderson broke in the following game and held serve.
Federer hadn't been broken until facing Anderson.
Coming back in the second set, Nishikori held his serve in a long first game and went on to break Djokovic after the Serb received a code violation for racket abuse, serving out to equalize at 1-1.
Anderson, a 32-year-old South African who played college tennis at IL, served it out, ending things with a 128 miles per hour service victor before raising both arms. Djokovic broke Nishikori's serve seven times, and finished with six aces.
However, Nishikori was prevented from launching a comeback as Djokovic, a three-time Wimbledon champion, regained his composure and managed to grind out wins in the third set (6-2) and in the fourth set (6-2) to set up a semifinal match against Juan Martín del Potro or Rafa Nadal.
The 12-time Grand Slam champion then raised his level in the fourth set and finished with a victor into the corner to book his place in Friday's semi-finals where he was joined by a familiar foe as Nadal won through late in the day.
"It was just one of those days where you hope to get by somehow", said Federer, who last played at No. 1 Court in 2015. I didn't harm the grass. Kei did the same in the fourth set but wasn't warned. (Ramos) said he didn't see it. "But hopefully I have two more matches to play". Only last month, after a French Open quarter-final defeat, Djokovic had raised doubts about even appearing on the grass of south-west London. "I like my chances against Nishikori", said Djokovic. "I've been building the last couple of weeks on the level of tennis I've played in the last couple of months".
"I like the level of tennis that I'm playing on right now". You have got people in all different languages swearing constantly all the time.
With Kevin Anderson taking nearly three and a half hours to tame French showman Gael Monfils in the previous match, Djokovic knew he had about two hours of daylight left if he wanted to avoid coming back on Tuesday's rest day to finish off the contest. "Double standards, my friend", screamed the former world number one.