SHANGHAI (AP) David Ferrer rallied to beat fellow Spanish player Feliciano Lopez 6-7 (5), 6-3, 6-3 to reach the finals of the Shanghai Masters on Saturday.

The fifth-ranked Ferrer, who clinched a spot in the ATP World Tour Finals this week, lost the first set for the third match in a row. Ferrer had saved three match points in his third-round win over Juan Carlos Ferrero and beat Andy Roddick in the quarterfinals in a third-set tiebreaker.

Although Lopez is ranked 23 spots below Ferrer, he had a 6-1 record against his countryman on hard courts coming into the match and had beaten three seeded players in straight sets on his way to the semifinals.

He had also beaten Ferrer two years ago in the second round in Shanghai.

I know the record with him, but I tried to refocus on my game,'' he said.I had confidence with me, with my game.''

Lopez was the more aggressive player in the first set, coming in behind his big serve and backhand slice repeatedly to finish off points at the net. After going down 4-1 in the tiebreaker, Lopez hit three big serves and a running backhand crosscourt winner to come back to take the set.

But Ferrer rebounded in the second, breaking Lopez in the third game when Lopez hit a slice backhand wide. He then got the decisive break in the third set when Lopez missed another shot badly wide while serving at 3-4.

Maybe today I played the better match of this week,'' he said.When I lost the first set, I tried to forget the tiebreak and I tried to focus again. I played better in the second and the third.''

Ferrer is attempting to win his first Masters-level tournament and will face either second-seeded Andy Murray or Japan's Kei Nishikori in the final. Ferrer played both of his potential opponents last week at the Japan Open in Tokyo, beating Nishikori in the first round and falling to Murray - the eventual champion - in the semifinals.