The world No.1 advanced to the last eight for a 14th straight year at the tournament with a 7-6 (9-7) 6-3 victory over Krajinovic.
Djokovic had not faced Krajinovic in more than a decade and said it was difficult facing off against one of his closest friends.
"It was one of the longest sets of my career," he said of the first set which lasted an hour and 27 minutes. "It is never easy to play against one of your best friends of so many years.
"We have only played 10 years ago in Serbia and he has changed as a person and as a player. It is rare that we have not played against each other in this decade. We trained several times together and we have played the Davis Cup together; it was good to play against him.
"Janko Tipsarevic [Krajinovic's coach], a Serbian tennis legend, is doing a great job with him. He's in the top 30; I know he's in shape.
"I did not start the game as I wanted. I made many unforced errors, but we must congratulate him for pushing me to the limit."
Djokovic saved five of six break points to seal the win after two hours and seven minutes, setting up a quarter-final clash with Dominik Koepfer.
He attacked Krajinovic's forehand with gusto and delivered a string of drop shots throughout the first set, but that game plan did not come off when holding two set points at 5-4 on his opponent's serve.
Krajinovic then started the tie-break strongly, storming into a 4-1 lead, before Djokovic powered back and took advantage of an error from his opponent to seal the set at the fifth time of asking.
Djokovic wasted little time moving through the gears at the start of the second set, driving forehands down the line to break serve at 1-1. He maintained his advantage to reach 5-3 before breaking serve again to seal the win.