"I think the second half of the season is going to be really, really interesting".
Mayer gave up a 5-3 lead in the opening set and went on to lose it in the tie breaker but he fought back hard in the next two sets to claim the win.
The 35-year-old has found his feet on grass at the most successful tournament of his career after his shock early loss to Tommy Haas in Stuttgart.More news: Pennsylvania issues permits to 12 medical marijuana growers
Mayer's record against Federer read seven defeats and no victories ahead of Friday's meeting, and he got off to a poor start in front of his home crowd when dropping his second service game.
Having cruised through on serve in the first set without a break point against him and dropping just two points from 20 first serves, Federer's level fell off a little, but he saved both break chances he faced.
Russia' Andrey Rublev returns a shot to Russia's Mikhail Youzhny at the Gerry Weber Open tennis tournament, in Halle, Germany, Thursday, June 22, 2017.
The third seed needed to take a medical time-out against Karen Khachanov to treat a back injury before playing on for a few points and retiring with the Russian leading 3-2 in the first set.More news: Senate Steers Toward Showdown Vote Next Week on Health Bill
The Swiss said: "Andy was exhausted after getting to number one at the end of past year and then has been struggling with injuries". He withdrew past year before his second-round match versus Mayer and retired in his 2015 semifinal against Andreas Seppi.
Error! There was an error processing your request.
Get daily prep sports headlines from the Gwinnett Daily Post staff delivered to your email.More news: NORC poll: Few favour Trump move to ditch Paris accord