The evergreen Federer did not drop a game in a dominant first set but was dragged into an intense battle by an inspired Monfils.
Madrid: Roger Federer survived two match points against French maverick Gael Monfils to extend his claycourt comeback and reach the quarter-finals of the Madrid Open on Thursday.
He was joined in the last eight by five-times Madrid champion Rafael Nadal and world number one Novak Djokovic.
The evergreen Federer did not drop a game in a dominant first set but was dragged into an intense battle by an inspired Monfils before prevailing 6-0, 4-6 7-6(3).
World number three Federer, playing his first tournament on clay for three years as he prepares for the French Open, surrendered the initiative after his brisk start and was in deep trouble in the third set when he trailed 4-1.
Federer struggled with his timing on occasions in breezy, sunny conditions and swatted a ball angrily over the stands when he dropped serve at the start of the decider.
But the 37-year-old Swiss broke back in the seventh game with a stunning sliced backhand return.
Monfils earned a match point at 5-6 on the Federer serve with an ice-cool backhand pass, but Federer followed in a second serve and bounced away a smash.
Federer saved another match point to set up a tiebreak and he proved unstoppable as he swept to his 1,200th match win.
Austrian Dominic Thiem, a beaten finalist in Madrid last year, awaits in the next round after he beat Italian Fabio Fognini.
“I think Gael did a nice job of not being frustrated losing the first set,” Federer said. “I lost five games in a row and it didn’t look good for a while but I hung in. There were some highly stressful moments but I mixed it up nicely.”
Federer’s fellow Swiss Stan Wawrinka, champion at Roland Garros in 2015, continued to produce some vintage form as he beat Japan’s Kei Nishikori 6-3 7-6(3).
World number one Djokovic was untroubled as he beat Jeremy Chardy 6-1 7-6(2) to set up a clash against Marin Cilic after the Croatian battled past Serbian Laslo Djere 4-6 6-3 6-2.
Spaniard Nadal, who later this month will aim for a 12th French Open, swept past unseeded American Frances Tiafoe 6-3, 6-4 while defending champion Alexander Zverev defeated Hubert Hurkacz 3-6, 6-4, 6-4.
World number one Naomi Osaka lost in three sets to unseeded Swiss Belinda Bencic in the Madrid Open quarter-finals on Thursday as Simona Halep, Sloane Stephens and Kiki Bertens completed the final four line-up.
“People have been telling me that if I get to the semis I stay at number one so I wanted to do that,” Osaka said.
“I wanted to do that and was thinking about it while I was playing, which wasn’t a good thing. I play my best when I’m calm and today I wasn’t, so that’s the biggest thing I can learn.”
Bencic will face two-times Madrid champion Halep in the last four after the Romanian beat ninth seed Ashleigh Barty 7-5, 7-5.
If Halep wins the tournament she will replace Osaka at the top of the WTA rankings heading into the French Open.
Stephens comfortably saw off Croatian Petra Martic 6-4, 6-3 to set up a semi-final with Bertens after the Dutch seventh seed stunned world number two Petra Kvitova 6-2, 6-3 in Thursday’s late match under the floodlights.
Osaka, 21, admitted she over-thought about the need to win the match in order to retain her ranking at the top of the women’s game as she went down 3-6 6-2 7-5.
The 21-year-old Japanese was a break up in the final set against Bencic, but was broken when serving for the match at 5-4 as the wind swirled despite the blue skies in the Spanish capital.