Murray captured his 26th career tour title, and second of the year after having taken the Brisbane crown, in a grueling two hours and 45 minutes.
"Both of us fought hard," Murray said. "Both of us were struggling physically at the end. I was lucky to come through."
Ferrer collapsed with a cramp two points from the finish and Murray took a stumble earlier in the final set in hot and humid conditions.
"I am tired. It was a very long match," Ferrer said. "Andy had more at the end. Congratulations to him."
The endurance test was the second Miami title for Murray, who also won in 2009, and among his toughest.
"It was a brutal, brutal match," Murray said. "Both of us were kind of on our last legs. It was one of the toughest matches I've had to play in a Masters Series, for sure.
"It was so tough physically and mentally that you were just trying to play each point. I wasn't thinking too much only because I was so tired."
Murray will rise to World No. 2, bumping his way ahead of Roger Federer, while Ferrer will move past Rafael Nadal to become fourth in the rankings, both men matching the best position of their careers with the improvement.
Nadal and Federer skipped this year's edition of the $8.5 million hardcourt event in Miami, which also included a WTA event won by Serena Williams, while World No. 1 Novak Djokovic lost in the fourth round.
Murray, who owns a home 10 minutes from the stadium, beat Ferrer, who turns 31 on Tuesday, for the seventh time in 12 career meetings. Ferrer's only win over Murray off clay was at the 2011 ATP World Tour Finals.
Ferrer, who has won this year at Auckland and Buenos Aires, failed in his bid to win his first US title and become the first Spaniard to win the Miami title. He is 0-12 in finals against players ranked in the world's top four.
"Tomorrow, sure, I'm going to be positive," Ferrer said. "I made the final. I know it was a very good chance to win Miami. It's very difficult but my life, it didn't change for one match.
"I need to work hard and to be focused for the next tournaments."
Ferrer, who fell to 21-5 on the season, apologized to supporters in the crowd he compared to those in his homeland for their passion, saying, "I'm sorry. I'm so sorry. One point. Next time."
Murray and Ferrer exchanged breaks over the first six games of the third set, then each held serve once before Murray broke Ferrer for a 5-4 edge when the Spaniard netted a forehand.
Murray served for the match but surrendered a break instead, Ferrer pulling level and then holding serve for a 6-5 advantage.
Ferrer reached match point in the 12th game on Murray's serve but stopped play on the key point to challenge on a Murray forehand that was ruled on the baseline, setting the stage for Murray to hold and force the tie-breaker.
"Luckily it just dropped in," Murray said. "It was centimeters away from being his match. That's probably why he didn't play such a strong tiebreak."
Ferrer said he had no regrets about the choice to put the outcome in the hands of the review system.
"I had my chance in the match point," he said. "The ball, it was really close. I saw out. I chose my decision in that moment. It's a bad moment now. I don't want to think anymore about that. I want to forget as fast as possible."
Murray roared ahead 4-0 in the tie-breaker and Ferrer collapsed to the court with a leg cramp after falling behind 5-1. He rose but was finished two points later by the Scot on a backhand winner, Murray improving to 14-2 in the year.
"I don't think either of us played our best," Murray said. "There were a lot of breaks and ups-and-downs, quite a lot of mistakes from both of us, but what I did do was fight hard, showed good mental strength to get through that match, because it easily could have slipped away from me."