The Australian Open champion had lost his previous two Masters finals and looked like losing a third until Federer's level dropped suddenly late in the second set, and Wawrinka began troubling the 17-time Grand Slam champion with his aggressive backhand.
The fourth-seeded Federer, who accepted a wild card invitation to play in the tournament, was also looking to win it for the first time after losing his three previous finals here to eight-time champion Rafael Nadal from 2006-08.
"It's exceptional to be able to win my first Masters title here," Wawrinka said.
It was the first time that Federer and Wawrinka met in a championship decider. In the last all-Swiss final, Marc Rosset beat Federer in Marseille in 2000.
More From This Section
With the third-seeded Wawrinka serving for the match, Federer shouted in frustration as he missed an easy forehand on second serve at 15-15. On the next point, Federer's backhand went wide and Wawrinka clinched the victory with a crisp forehand winner that landed on the line.
"I had a great week here," Federer said. "Congratulations to Stan."
It is the seventh title of the 29-year-old Wawrinka's career, and his third this year. He lost his previous Masters finals at Madrid last year and Rome in 2008.
Federer broke for a 3-2 lead when Wawrinka's backhand long, and served out the first set when his countryman over-hit another backhand.