The Swiss top seed, who skipped the entire European claycourt swing to concentrate on the grasscourt season, showed signs of rust early on against Zverev but it did not take too long for him to rediscover his rhythm.

Federer had some early chances but could not take them and it was Zverev who struck first when he broke to love to lead 5-3 before a couple of aces helped him pocket the opening set.

It was the first set Zverev, older brother of world number three Alexander, had ever taken from Federer in six attempts, and a shock looked on the cards when he had a break point in the opening game of the second set.

Federer, who will be seeking a ninth Wimbledon title next month, eventually found some magic with a backhand winner to break for a 4-2 lead but the 36-year-old handed the advantage straight back in the next game.

Veteran Tommy Haas stunned Federer in Stuttgart a year ago but any thoughts of a similarly early exit against Zverev vanished as he surged into a 4-1 lead in the second set and cruised to victory.

“Three months is a long time, it’s longer than the year-end break,” said Federer, who had not played since March.

“So I’m very happy returning on good terms onto the Tour. It’s difficult, missed some chances maybe in the first set... He connected well at the right times. Then I found my rhythm. I’m super happy to be back on Tour. It’s been a great start.”

Second seed Lucas Pouille also moved into the third round with a straight sets win over German wildcard Rudolf Molleker but sixth seed Denis Shapovalov was surprisingly beaten by 169th-ranked Indian qualifier Prajnesh Gunneswaran.

Milos Raonic, the Wimbledon runner-up in 2016, eased into the second round with victory over Mirza Basic.