The 46th-ranked Mayer saved five of the eight break points he faced and converted five of his seven chances to beat the seventh-ranked Spaniard in the clay court tournament.
''I can't believe it,'' Mayer said. ''I was able to do it against Ferrer, who is one of the best players on this surface. I'm really happy and it still hasn't sunk in that I won.''
Mayer had not dropped a set in five matches to reach the final, while the 32-year-old Ferrer had been bidding for his 22nd title.
''He was better in the match,'' Ferrer said. ''I think I was little bit nervous in the important moments and he played more aggressive than me, and nothing else.''