His run to the final in Germany ensured he usurped previous world No 1 Rafael Nadal at the top of the ATP rankings, and if he wins in Halle next week - a traditional Federer stronghold - he will arrive at Wimbledon in July looking for his 100th title on tour.
The 36-year-old will need to defend his title at Halle to maintain his No. 1 spot ahead of Wimbledon.
Federer was pushed all the way by the fourth-seeded Kyrgios, who fired down 23 aces in another battling performance at the German grasscourt tournament.
Roger Federer defeated Guido Pella 6-4, 6-4 on Friday to advance to the Stuttgart Open semifinals. "I'm playing better with each match, I'm there at the important moments in the games, that's an important thing".
"I'm really happy. I thought it was a good final from my side".More news: Musk company to build Chicago-to-O'Hare express transport
More news: India Vs Afghanistan: Indian PM congratulates teams for the historic event
More news: Former propaganda artists for North Korea denounce Trump-Kim meeting
The 20-time Grand Slam champion did not earn a single break point during the final set, but when it came time for another tie-break to decide the contest, he was able to win the points that mattered, narrowly edging it 7-5 to book his place in Sunday's final.
Raonic saved the only two break points of the match and then was victorious in both tiebreakers. "I fought hard. When you finally manage it, the joy is even greater", said Federer, who extended his grass-court winning streak to 16 matches including his titles at Halle and Wimbledon past year. "I hadn't played in three months, it's on grass, it's fast and hard to get so far here".
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. "There is a big difference between playing a semi and a final".
Roger Federer became the world No. 1 for the sixth time in his career.
"For me, when talking about that consistency, I think I have shortened the gap between my high level of tennis and the level where I am floating sometimes", he added.