The Swiss maestro is just a single victory away from reclaiming the No. 1 ranking thanks to a hard-fought 7-6 (8-6), 7-5 second-round victory over Germany's Philipp Kohlschreiber at the ABN AMRO World Tennis Tournament.
The 36-year-old Swiss great already has the record for most weeks as the ATP World Tour's No. 1 player (302) but he has not held the top spot since late 2012.
Now only the Netherlands' Robin Haase, a 6-4, 6-0 winner late Thursday night over Dutch wildcard Tallon Griekspoor, stands in his way.
Kohlschreiber, who had never defeated Federer in a dozen previous matches, took a 5-2 lead in the first-set tiebreaker and then had a pair of set points at 6-4.
Federer recovered, however, to get the tiebreaker level and then create four set points of his own, finally converting the last one by hitting a forehand winner.
The second set also was very closely contested, but Federer got a crucial service break in the 11th game and then served out the match in his first opportunity.
"It was extremely complicated tonight," Federer was quoted as saying afterward on the ATP World Tour's Web site.
"I couldn't find my range or my rhythm. I think Philipp did that to me; it was a struggle. Today when the score was close, I couldn't release my shots. So it was a battle."
In Friday night's quarter-finals at this indoor hard-court event, Federer will try to extend his perfect record over Haase to 3-0.
He won their previous two matches in straight sets.
If he can do so, he will become the oldest player to hold the ATP No. 1 ranking. American star Andre Agassi currently has that distinction, holding that ranking for the last time at age 33 years and 131 days.
Federer dropped out of the top 15 of the rankings when a knee injury forced him to shut down his 2016 season prematurely, but he has made a remarkable comeback to the game since January 2017.
He won the Australian Open and Wimbledon last year and then extended his record haul of Grand Slam titles to 20 last month by successfully defending his Australian Open title.
(With IANS Inputs)