* Scot passes Federer in rankings
* Murray survives big scare for victory
* Ferrer's solid play gives him first set (Adds detail)
By Simon Evans
MIAMI, March 31 (Reuters) - Britain's Andy Murray defeated Spain's David Ferrer 2-6 6-4 7-6 in a gruelling and enthralling Sony Open final on Sunday to move above Roger Federer to second in the world rankings.
Murray was far from at his best against a dogged Ferrer but won the tie-break 7-1 after surviving a scare when the Spaniard had match point at 6-5 up, with Murray serving, in the third.
Murray's forehand landed close to the line and he faced a challenge from Ferrer, who called out rather than play the shot, but the ball was shown in, and the Scot won the next two points to force the tie-break.
"It was such a tough match, it could have gone either way, both of us were struggling physically at the end," said Murray whose victory was his second at Miami following his triumph in 2009.
"It's so tough against him. He has a great attitude, he's a great fighter. I am sure we will have more tough matches in the future."
The last time Murray, who is behind Novak Djokovic in the world rankings, was ranked second was back in 2009 when Federer was the top player.
LOTS OF ERRORS
The match was littered with errors, particularly in the third set when neither player could hold serve in the first six games.
But it was a gripping duel in the mid-day heat at Key Biscayne with neither player flinching as they scrapped to the end.
The victory was Murray's ninth in a Masters 1000 series event and the U.S. Open and Olympic champion drew on all his reserves of energy to secure it.
Ferrer, enjoying plenty of support from the many South Americans in the crowd, won the first set with solid tennis, making the most of the openings offered by Murray.
The Spaniard won all three of his break points, while Murray committed 19 unforced errors, including four in the final game and gave up his third double fault on set point.
The second turned in Murray's direction when he broke to go 2-1 up and then, serving at 3-2 up, he saved two break points.
Ferrer broke back to level the set in the eighth game but Murray broke straight back and held to send the contest into a third set.
The two exchanged six breaks to begin the deciding set before Ferrer managed to hold to grab a 4-3 lead.
Just as his opponent sensed victory, Murray won two straight games to get in control, serving for the match at 5-4 up.
But Ferrer, in no mood to roll over, provided another twist in the plot as he broke, Murray failing to return on the crucial point as he slipped on the baseline.
Both men then held serve, Murray helped by the Hawk Eye technology on the decisive call while facing championship point.
"That is the beauty of the challenge system," said Murray. "In some matches that would have been over. It just dropped in."
The only surprise left was that the tie-break was not extended, Murray romping to a 7-1 win as his strong serve emerged at the most opportune moment.
"Neither of us played our best tennis," said an exhausted Murray.
"But it was good to get there in the end".
(Editing by Gene Cherry)