Kyrgios grabbed a fast 2-0 lead after unleashing a flying forehand pass on the stretch but Federer rallied back to move 5-4 ahead before a flicked effort at the net confirmed his place in the final 6-7 (2-7) 6-2 7-6 (7-5).
The third set was tight all the way into the tiebreaker, with Federer erasing a 3-1 deficit.
Raonic's serve proved the decisive factor yet again as he released 19 aces during his match with defending champion Lucas Pouille earlier on Saturday and he is yet to drop a set in Germany.
"I'm playing better with each match, I'm there at the important moments in the games, that's an important thing".
"I didn't give Guido many chances to get into my service games, except maybe the last couple", Federer said after only his second match since March 24.
Raonic, meanwhile, earned his fourth straight-sets victory of the week by dispatching Pouille to reach his first final since the 2017 Istanbul Open.
Nick Kyrgios put up a stirring fight
And because of the vagaries in the tennis ranking system, the win saw Federer replace Rafa Nadal as the World No 1, despite the Spaniard coming off victory at Roland Garros.
"But I [will] stop when I feel that my tournament life is no longer good for the family".
"It's a really positive step forward for me", he said. I've come back from not playing the last few weeks and I've come back playing at a high level. Federer, who beat Raonic en route to winning Wimbledon a year ago, broke the Canadian's powerful serve just once in the third game but with his own delivery proving unbreachable, it was enough for him to win the first set.
Entering the tournament, Raonic had been slipping in the ATP rankings, falling seven spots from 28th to 35th in the world.
He said: "It's not like one of my four-year-old sons comes to me and says "Dad, that's enough". "I've taken care of my serve. I've played well throughout those as well".