The 29th-ranked Spaniard displayed some impressive skills at the net and, combined with a fierce serve and strong backhand, he offered the Swiss world number one a real challenge.
"I really had to fight hard and I think he's definitely going to win his first title soon," said Federer.
"He played unbelievable tennis, I thought. I played good tennis except for that first game, and he came up with some unbelievable shots, unbelievable power, great serving and he totally deserved that first set.
"This means very much to me, to come back from a set down in a final. I don't remember if I ever did this before. Except for that first game I thought I played a perfect match," added the 22-year-old Wimbledon champion.
Federer started poorly, dropping his serve in the opening game with a mis-hit forehand.
Although Federer increasingly placed him under pressure, Lopez held on by firing six aces, holding off five break points at 4-3 and another as he served for the set.
But the second set saw a turnaround and Federer, who came close to defaulting their previous match at Wimbledon last year because of a back injury, began moving smoothly and broke to lead 3-1 with a fine forehand volley.
Another break for 5-1 when Lopez made a backhand error all but sealed the set, and Federer increased his dominance in the third, dropping just four points on serve.
Striking the ball cleanly and volleying with confidence, he forced a forehand error to break for 2-1 and took a decisive 4-1 lead when Lopez netted an inside-out forehand.
"I was playing so good at the beginning and really had a chance to be up in the second set," said the 22-year-old Lopez, who was appearing in his first ATP final.
"But I'm happy because I played great tennis this week and I was close today against the best player in the world.
"I was playing wonderful tennis in the first set and it wasn't easy to keep going at that level," he said.
More from rediff