After nonchalantly striding through the opening set amid effortless calm, Federer suffered a second-set wobble as the world number 89 responded to a partisan home crowd to convert his first break point of the match to level.
But as the glimmer of an upset began to poke through the sombre Parisian sky, Federer righted the listing ship, breaking twice in the third before edging out a resilient Mahut in the fourth.
The Swiss number three seed will now face Belgian
"I knew he could play very well from the baseline if he had time," Federer told reporters.
"I think for bigger guys it's about if you're able to move them around enough and they have to defend time and time again. This is maybe where you can expose some of their weaknesses.
"But if they're obviously on the attack and they can keep the points short, as he showed especially in the first few shots of each point, it makes him tough to play."
Mahut at times unsettled Federer with his frequent forays to the net and there was none of the attritional pounding so often a feature of the claycourt slam as both players leant heavily on their attacking instincts.
"I believe today he played average, but I believe it is maybe because of my game that he wasn't able to play better," Mahut said.
"I believe my game is a game that he is not used to on this type of surface.
"Usually he plays opponents playing from the baseline, hitting hard, but I deprived him of that.
"After a while, he couldn't find his rhythm and he made unusual errors, and I was able to force him to play bad in a way."
World number one
Djokovic had to wait until nearly 8pm local time to start his match thanks to some lengthy men's matches on Court Suzanne Lenglen, and he appeared keen to finish with Devilder as soon as possible as he withstood an energetic and adventurous display to win 6-1 6-2 6-2.
The shot of the match was the shot that finished it when, after an entertaining rally, Djokovic somehow met a zipping drive on the run to flash it past Devilder at incredible pace.
Next for Djokovic is
Fognini did his best to unsettle Tsonga with his histrionics and whipping shots, but the fifth-seeded Frenchman managed to stay focused even though he dropped his serve five times.
Despite the humid conditions on Court Philippe Chatrier, Tsonga, the last Frenchman to reach a grand slam final, at the 2008 Australian Open, had too much power for the world number 45.
Fognini berated the umpire and the partisan crowd following a few close calls, but Tsonga kept his composure to end his opponent's resilience with an ace.
Tsonga now faces
Berdych had to come from 2-1 down to eventually win 6-3 4-6 6-7(4) 6-4 6-4 and will now face
Ninth seed Del Potro safely negotiated a potential banana skin in
World number 109 Goffin, who beat France's Arnaud Clement and Czech 23rd seed Radek Stepanek in the previous rounds, is the first lucky loser to reach the fourth round of a grand slam since compatriot Dick Norman at Wimbledon in 1995.
The baby-faced Goffin, who had lost in the third round of qualifying, was inserted in the main draw after France's Gael Monfils pulled out injured.
In front of an ecstatic flag-waving Belgian crowd on the tiny Court 7, Goffin outplayed Kubot, the world number 49, wrapping it up after two hours and 32 minutes with a jaw-dropping forehand passing shot.
Elsewhere, 20th seed
Granollers now faces Paul-Henri Mathieu in the third round after the Frenchman's epic victory over Jon Isner on Thursday.