The Swiss saved had to save two break points in the second set before prevailing 7-6 (2) 7-6 (1) to set up a last four match-up with exciting young Austrian Dominic Thiem.
It was a victory with marked Federer’s 1072 win on the ATP tour, one more than Ivan Lendl, meaning only Jimmy Connors – on 1256 - has more than the 17 times major champion.
Federer, who has missed the last month with a back injury, showed signs that he was getting back to best, but often needed his reliable serve to bail him out of trouble on the speedy grass court.
Following his three set victory over talented teenager Taylor Fritz in the opening round yesterday, Federer was again pushed by Mayer, who has only just returned to the tour after a torn tendon in his right adductor kept him side-lined for over a year.
Encouraging tournament for Mayer
The 32-year-old German can take encouragement from this tournament; after coming through qualifying he beat sixth seed Viktor Troicki to reach the quarter-finals.
If he stays clear of injuries then Mayer’s current ranking 226 will certainly drop, and he is scheduled play at the tournament in Halle next week. However on this occasion his lack of match practise proved his undoing on the big points.
Federer saved two break points in the opening game of the match before both players settled into a comfortable rhythm on their own serves.
That was until the twelfth game when Mayer found himself facing a set point at 30-40, however it was saved when Federer shanked a backhand which dropped beyond the baseline.
Federer finds his best at the crucial moments
Even so it was the Swiss who dominated the subsequent tie break with some exquisite serving, before taking it by seven points to two.
Both players showed their expertise on grass, with a number of successful charges to the net and clever slices which skipped off the zippy surface.
Mayer made the perfect start to the second set by breaking the Federer serve for the first time to lead 2-0.
However the German was pegged back immediately, and missed his chance to level the match at a set a piece when Federer saved three break points at 5-6.
The Swiss then claimed another one-sided tie-break to seal the match in an hour and 25 minutes. He will be back on court tomorrow to face Thiem in the semi-finals.