Federer has never lost to Mayer but Friday marked the first time he dropped a set to Mayer in five meetings. Federer eventually prevailed 7-6 (7-4), 3-6, 7-5.
Mayer had more breaks (five to Federer's four) and won more points overall (105-100) but Federer converted all three of his break chances in the third set to get to the semifinals.
There he'll face qualifier Federico Delbonis, who edged past 14th-seeded Fernando Verdasco 6-7 (5-7), 7-6 (10-8), 6-4 in 3 hours, 14 minutes. It was the second time in the tournament Delbonis ousted a seeded player.
He fought off 10 break points before winning the lengthy second-set tiebreaker -- Verdasco saw none in the set -- and then posted three third-set breaks to advance.
No. 12-seeded Fabio Fognini ousted second-seeded Tommy Haas 6-2, 6-4. Fognini had four breaks and won half of the points when Haas served.
Almagro takes on Fognini in Saturday's first semifinal. Almagro has won three of their previous four meetings. Federer has never before played Delbonis.
The formal name of the tournament is the best-at-home Open-German Tennis Championships.
Notable deaths of 2014 [PHOTOS]