You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
Federer overcame an unexpected challenge from "lucky loser" David Goffin to move into the last eight with a 5-7 7-5 6-2 6-4 victory over the young Belgian.
The 16-times grand slam champion will play either Czech seventh seed Tomas Berdych or ninth-seeded Argentine Juan Martin del Potro on Tuesday for a semi-final berth.
Del Potro led Berdych 7-6 (8-6) 1-6 6-3 when their fourth-round match was suspended due to fading light.
Djokovic's quest for a non-calendar-year grand slam almost came to an abrupt halt when the Serb went down two sets to love against Italian Andreas Seppi.
But Djokovic rallied for an epic 4-6 6-7 (5-7) 6-3 7-5 6-3 triumph over the 21st seed to avoid bombing out on the same gloomy day in Paris as women's world No.1 Victoria Azarenka.
"I played very badly, but I won thanks to my fighting spirit," said Djokovic, bidding to become just the third man to hold all four majors at the same time - and first since Rod Laver in 1969.
"He was the better player for the first two sets and I was fortunate to come through.
"But even at two sets down, I still believed I could do it and that's about the only positive I can take. It was one of those days when nothing worked."
The Serb will meet either French fifth seed Jo-Wilfried Tsonga or Swiss 18th seed Stanislas Wawrinka in Tuesday's quarter-finals.
Tsonga will resume on Monday leading 6-4 7-6 (8-6) 3-6 3-6 4-2 with a service break in the deciding set.
For a couple of hours on Sunday there appeared every chance that both top seeds plus Federer would crash out in what would have been the biggest day of upsets in more than a hundred years of grand slam tennis.
With Azarenka already eliminated, Djokovic stood two games away from defeat on Court Philippe Chatrier as Federer trailed by a set and 5-5 on Court Suzanne Lenglen.
Two hours later and order was restored, with Federer denying the gallant and entertaining Goffin a place in tennis history and Djokovic's grand slam tilt still intact.
"I didn't know much about Goffin beforehand, but I know him a lot better now," said Federer said.
The 109th-ranked Goffin, a baby-faced 67kg lightweight who grew up idolising Federer, had been striving to become the first lucky loser to make the quarter-finals of a major after faltering in the qualifying event.
"I have no regrets, I gave it all I could," Goffin said.
"It was a very nice match. I was tired by the end because I have played a lot of matches at this tournament."