The Swiss ace beat his Spanish counterpart 6-3 1-6 6-2 to clinch an 80th career title - and first Masters 1000 success in two years.
Federer, a five-time US Open champion, now turns his attentions towards New York next Monday as he eyes up a first Flushing Meadows title since 2008.
"I'm happy how I'm playing," he told reporters.
"I know I didn't beat Rafa [Nadal, absent injured] and Novak [Djokovic, a third-round casualty] here but you can only beat who you play.
"Clearly I can't wait for the US Open but I need some rest too."