Earlier, Serena Williams overpowered the top-ranked Victoria Azarenka 6-1, 6-3 to win the women's final.
While Novak Djokovic and Rafael Nadal had blamed the new blue-clay court for their early exits, Federer's biggest obstacle was to overcome an opponent who had beaten him in three of their previous five meetings.
"It is amazing to win here again," said Federer, who will overtake Nadal as the second-ranked player behind Djokovic. "It has been a tough tournament. Tough to move, but you've got to try to make the most of it. Here there was some good tennis and some bad tennis, but you see that in all tournaments."
Berdych hit 14 winners and made just two unforced errors in a dominant first set. However, Federer finally found his ground game and broke Berdych twice to even the score and force the decisive third set, where he secured victory after Berdych had saved three championship points.
The sixth-seeded Berdych jumped out to a 3-0 lead after hitting a crosscourt return to take Federer's first service game.
Federer, who won here in 2006 and 2009, saved two set points before Berdych clinched the first set with a big serve that the Swiss star could only knock back into the net.
Federer continued to struggle with his shotmaking, but the 16-time Grand Slam winner levelled the match by breaking twice in the second set, including when Berdych hit a double fault on set point.
"It was a tough tournament and a brutal draw. Tomas played very well," said Federer. "I'm sure we will see each other many more times and they will be quality matches like this one."
Berdych, who had carried the initiative through most of the match, became erratic as the pressure grew in the decider.
Serving to send the match to a tiebreaker, he fell behind 0-40 and then rallied back to force deuce, only to hit long and then net his final volley to end the match in just over two and a half hours.
The former top-ranked Federer has not been higher than No. 3 since March 2011.
"I want to congratulate Roger. He showed that he is really the star," Berdych said.
In a clash of two of the tour's heaviest hitters, Williams battered Azarenka around the court with her big serve and vicious return to take the first four games and never looked back.
Williams served 14 aces on her way to her 41st career title and second of the season as she remained unbeaten in her last 13 matches on clay.
The loss ended Azarenka's run of winning her last four tournaments.
"I can still do better," Williams said when asked if she had found her best form following her return from a lengthy absence due to illness in 2011. "This is really good. I have been working hard. I had some tough battles and really unfortunate circumstances so I really love this."
Williams broke Azarenka's first service game when the Australian Open winner could only stab her powerful return into the stands.
William's strong start left Azarenka shaken, and she hit three double faults to cede her serve again and trail 3-0.
The flustered Azarenka netted a forehand after Williams had fallen on the slick surface and left the entire court open. She then produced another double fault to cap a disastrous first set.
Williams kept the momentum going, hitting her fifth and sixth aces to hold to love at the start of the second set.
As her frustration boiled over, Azarenka smashed her racket into the ground moments before Williams blasted a return by her to break her yet again.
The 13-time Grand Slam winner sealed the victory in 1 hour, 4 minutes with her final ace.
"She was so much better than me today," Azarenka said. "I have to give her credit, she's been showing great tennis the whole week."Suggest a correction