Federer, seeded third at the event, racked up his fourth title of the year with a 3-6, 7-5, 7-5 decision.
It was the Swiss superstar's 74th career title, 20th Masters crown -- tying him with Spain's Rafael Nadal -- and his third in Madrid following championships in 2006 and 2009.
He became the event's first three-time winner with Sunday's triumph.
No. 6 seed Berdych of the Czech Republic fell short in his bid for a second 2012 title of after taking Montpellier in February.
Megyn Kelly: Santa Claus and Jesus are both white men
Wisconsin business offering 'therapeutic cuddling' forced to close