The second-seeded Serb won 6-3, 6-2, 6-7 (2), 6-4 against Marin Cilic, improving to 9-0 in their head-to-head meetings, but looked sluggish at times.
Federer, meanwhile, was in total control before wasting four set points in the second set on his way to a 7-5, 6-7 (7), 6-2, 6-4 win against Dmitry Tursunov.
"He played really well and went for big shots," Federer said. "It was difficult to finish the match, so obviously I'm relieved."
Djokovic dropped serve early to trail 3-1, made sloppy unforced errors in the tiebreaker, and was broken back in the fourth set after leading 4-2. He sealed the victory on his first match point when the 25th-seeded Croat double-faulted.
More From This Section
Djokovic is looking to win the French Open for the first time and lost to eight-time champion Rafael Nadal in the semifinals last year.
Federer, who had won his opening two matches in straight sets, converted only four of his 21 break-point opportunities against the 31st-seeded Russian.
The 17-time Grand Slam champion even joked when asked moments after the match if his poor conversion rate worried him.
"I pretend there isn't a problem," he said, breaking into a huge grin. "I'll go for the next one, and the next one, and the next one."
Federer is trying to win the title at Roland Garros for the second time. He is the 2009 champion, but lost in the quarterfinals last year.