The 36-year-old will need to defend his title at Halle to maintain his No. 1 spot ahead of Wimbledon.
Federer now goes through to Sunday's final where he will aim for a 98th career title against Canada's Milos Raonic, who won his last title at the 2016 Brisbane International. I've come back from not playing the last few weeks and I've come back playing at a high level. "We've played so many breakers already, I'm losing count", Federer told the ATP website.
Federer's 78-minute win, sealing his first Stuttgart triumph, was the flawless tonic for the Swiss in the build-up to defending his Wimbledon crown, having extended his unbeaten 12-month sequence in grass court matches to 16. "I thought maybe it was going to happen again but when I picked up the half-volley I was so happy".
The Swiss broke twice in the first set to earn it after 32 minutes when his opponent returned long over the baseline.
However Federer didn't have things all his own way against the big-serving Canadian, Raonic, who slammed 14 aces during the two-set encounter.
In a mirror image of the first set, the two players were locked on serve until they were separated by an ultimate tie-breaker.
Federer improved to 21-2 on the season after playing in the 24th grass final of his career.
Next week, he will open his Halle bid in the first round against Aljaz Bedene.
"It will be a hectic 48 hours", said Federer.
Federer's 78-minute win, sealing his first Stuttgart triumph, was the ideal tonic for the Swiss in the build-up to defending his Wimbledon crown, having extended his unbeaten 12-month sequence in grasscourt matches to 16.
"It will all depend on how many matches I get next week and then I'll decide what to do in the week before Wimbledon", Raonic said.