The Grand Slam record-holder from Switzerland was 1-4 down in the first set against Fernando Verdasco, the former world number seven from Spain, before producing a faultless five games of attacking, much of it launched from the net, and going on to win 6-4, 6-3.
Federer's stunning sequence began after Verdasco had held serve with the help of a startling badminton-style jump smash, concluding the game with an inside out forehand drive which was untouchable.
It took the 33-year-old less than quarter-of-an-hour to complete the turnaround, which was continued by an immediate break of serve in the second set, and during which he charged forward like an old-time Wimbledon grass court player.
"The score wasn't good but I was feeling okay so I didn't want to psych myself out," Federer commented.
"I wasn't doing much wrong — I was feeling like I was hitting the ball well," he said.
"So I am really pleased I got control somehow. I didn't realise it was so many points in a row."
Federer next plays Richard Gasquet, the former top ten Frenchman.
Gasquet overcame Roberto Bautista Agut, the seventh seeded Spaniard, 6-4, 3-6, 7-6 (8/6) recovering from 4-2 down in the final set for the second successive time (the first was against Andreas Seppi on Monday) and saving a match point at five points to six down in the final set tie-break.
"I'm looking forward to playing him again – the last time we played was in that Davis Cup final", said Federer, referring to the decisive fourth rubber at Lille three months ago.
"There was a lot of pressure. This time should be more relaxed.
"He has had a great start to the season, winning a title (Montpellier). He had a tough win today but that gives him a lot of match time and court time. I just love his backhand and it is always a pleasure to play against him."
The other leading contender, Novak Djokovic, the world number one from Serbia, will also face an unseeded player after overwhelming Andrey Golubev, a Kazak ranked outside the top 100, by 6-1, 6-2.
It earned him a meeting with Marsel Ilhan, a qualifier from Turkey who won 3-6, 7-5, 6-3 against Feliciano Lopez, the sixth-seeded Spaniard who has twice been a finalist here.
Earlier, Andy Murray, a potential semi-final opponent for Federer, won 6-0, 6-2 against Joao Sousa, the world number 50 from Portugal, his most emphatic result against a top 50 player for almost six years.
However, the former Wimbledon and US Open champion now plays, according to Djokovic "definitely one of the most talented players right now the world."
That is the 18-year-old Borna Coric, a Croatian who reached the draw as a lucky loser was also a slightly lucky winner.
Or at least he had a slice of good fortune in surviving against Marcos Baghdatis, the former Australian Open finalist, who led 5-3 in in the final set before retiring with cramp at four points all in the final set tie-break
Earlier, the man seeded to meet Djokovic in the semis, Tomas Berdych scored his 500th tour win, a 7-6 (9/7), 5-7, 6-0 success against Simone Bolelli of Italy, which made the Czech the eighth active player to achieve that landmark.