World number three Roger Federer is playing his first tournament on clay for three years as he prepares for the French Open.
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.
The evergreen Swiss 37-year-old 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 he 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 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 Novak Djokovic was untroubled as he beat Jeremy Chardy 6-1 7-6(2) to set up a clash against Marin Cilic.
Spaniard Rafael Nadal, who later this month will aim for a 12th French Open, faces American Frances Tiafoe later while defending champion Alexander Zverev plays Hubert Hurkacz.