Roger Federer will be back as World No 1 in the new rankings next week after coming from behind to beat Nick Kyrgios 6-7 (2), 6-2, 7-6 (5) in the semi-finals of the ATP Mercedes Cup in Stuttgart.
The 36-year-old Swiss will play Canada's Milos Raonic in Sunday's final.
Federer, who has won 15 successive matches on grass since being beaten in his opening match in Stuttgart last June, knew he had to win on Saturday to topple Rafael Nadal from the top of the rankings. He will begin a record-extending 310th week at the top on Monday.
But he was made to work hard for the honour as Kyrgios, playing in his first tournament after two months out with an elbow injury, refused to buckle in a contest that lasted just short of two hours.
Over their three career matches, eight of their nine sets have now gone to tiebreak and there was little to separate them in Stuttgart where Federer conceded first, forced his way back into the match and then was taken all the way in the third.
In the other semi-final, Raonic beat defending champion Lucas Pouille 6-4 7-6(3) to reach his first final since 2017 Istanbul Open.
The seventh-seeded Canadian has not won a title since the 2016 Brisbane International.