The top seed and world number three will face Tunisia’s Malek Jaziri, ranked 64, for a place in the last eight, as he steps up his bid for another tilt at the Wimbledon title.
“It was hard to find a rhythm today. He took the ball early, went for a lot on the forehand, backhand. He has a big serve, especially the first one,” Federer said.
“So then you go back to basics, you focus on your own serve. I thought I did that very well. He never really had chances on my own serve, so that was comforting.”
The 34-year-old Federer, who has now won 52 matches in his Halle career, has yet to win a title in 2016, his longest drought to start a year since he went title-less in 2000.
But Wednesday’s tie was just his 19th match of the season after he struggled with a back injury and endured knee surgery in February.
His injury woes forced him to skip the French Open, ending his record run of 65 successive Grand Slam appearances stretching back to 1999.
Last week, 17-time major winner Federer made the semi-finals of the Stuttgart grasscourt event, where he lost to Dominic Thiem, who went on to take the title.
Later this month, Federer will begin his bid for an eighth Wimbledon title when the third Grand Slam tournament of the season starts on June 27.
“I feel after the first round, after having played last week, actually maybe something is really possible here,” added Federer.
“I don’t want to get too carried away but I feel like if I serve the way I did today and I’m able to step it up just a little bit on the return from the baseline, all of a sudden I’m dangerous for anybody.
“We’ll see how it goes. But I take one match at a time and I hope just to keep on playing a bit better match by match.”
Japan’s world No 6 Kei Nishikori suffered a pre-Wimbledon blow when he was forced to pull out of the Halle tournament with a rib injury.
Nishikori, seeded two in Germany behind Federer and a semi-finalist in 2014 and 2015, was to play Florian Mayer, who was given a walkover into the quarter-finals.
“I’m very sad to not be able to go on playing,” said Nishikori, whose status for Wimbledon is not yet certain.
German teenager Alexander Zverev made the quarter-finals when compatriot Benjamin Becker, 16 years his senior, withdrew with an injury at 7-5, 3-0 down.
Zverev will next meet Cypriot veteran Marco Baghdatis who put out Dustin Brown, also of Germany, 7-5, 7-6 (10/8).
Philipp Kohlschreiber, the Stuttgart runner-up, enjoyed a 6-2, 7-6 (7/4) win over Spanish clay courter Marcel Granollers.
PTI