Roger Federer defeated Nick Kyrgios 6-7 (2), 6-2, 7-6 (5) to book his place in the Stuttgart Open final and reclaim the No. 1 ranking from Rafael Nadal on Saturday.
The Swiss great will play Milos Raonic as he bids for his 18th grass-court title.
Raonic earlier hit 19 aces and saved the only break point he faced as he defeated defending champion Lucas Pouille 6-4, 7-6 (3) in the other semifinal.
Federer was pushed all the way by the fourth-seeded Kyrgios, who had 23 aces.
Kyrgios forced a mini-break in the deciding tiebreak, but Federer remained steady and sent a short backhand past the Australian on his first match point to clinch the win.
Federer, in his first tournament since March, was trailing Nadal by 100 points at the start of the week and is guaranteed of taking the top spot on Monday regardless of how Sunday's final goes.
It will be Raonic's first final since the 2017 Istanbul Open. The Canadian won his last title at the 2016 Brisbane International.