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.
"I'm pleased I found a way and played it solid and tough toward the very end," Federer said. "When somebody serves big like he does, it's sometimes a bit difficult."
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.
The six-time Grand Slam champion next plays either 13th-seeded Jo-Wilfried Tsonga of France or No. 22 Jerzy Janowicz of Poland, who played later Friday.
Djokovic is looking to win the French Open for the first time. He lost to eight-time champion Rafael Nadal in the semifinals last year.
In the tiebreaker, Djokovic's weak drop shot at 6-2 down gave Cilic an easy chance to whip a forehand winner.
Frustration got to Djokovic in the eighth game of the fourth set, with the player shaking his head when another Cilic shot clipped the net and bounced in to give him a break point.
Djokovic vigorously pumped his fist after saving it but then gave another chance with a backhand into the net. He got out of trouble with a strong serve that Cilic returned into the net, but Cilic took his next chance, breaking back to 4-4 with a backhand volley at full stretch at the net.
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, whether 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."
He's done far worse recently. In his quarterfinal win against Tsonga at this year's Monte Carlo Masters in April, Federer wasted 15 straight break points.
Tursunov was trailing 0-40 in the 12th game and 7-6 down in the tiebreaker but went on to level the match with a forehand pass down the line.
"I wish at times I could have played a bit more offensive," Federer said.
Shortly after winning the second-set tiebreaker, Tursunov appeared to have a minor meltdown while trailing 2-1 in the third. He argued with the chair umpire and took a medical timeout. He left the court for several minutes.
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. The Swiss star next plays No. 18 Ernests Gulbis of Latvia, who reached the fourth round here for the first time since 2008 -- the year he reached the last eight -- after beating Radek Stepanek 6-3, 6-2, 7-5.
"I don't want to tell all my cards. But I have a game plan," Gulbis said. "You don't need to be scared to do certain things against him."
Federer leads Gulbis 2-1. All of those matches were in 2010, and they are 1-1 on clay.
"I'm aware of the challenge ahead of me," Federer said. "I have had some tough matches with him in the past."
The Associated Press contributed to this report.
Djoker Labors To Beat Cilic
Novak Djokovic beat Marin Cilic for the ninth straight time, 6-3, 6-2, 6-7 (2), 6-4 to reach the fourth round of the French Open.