Murray dropped the third set after squandering a match point but the British number one produced his scintillating best in the fourth to win 7-6 (7/4) 6-2 5-7 6-1.
It is Murray’s first victory over Ferrer on clay and means he will now face Djokovic in the semi-final after the Serb ousted nine-time French Open champion Rafael Nadal.
“I knew it was going to be a tough match today,” Murray said.
“The third set was a tough one to lose, he fought back and made it very difficult.
“The groundsman watered the court and I went to the bathroom to take a few minutes and get my composure back. That helped.
“I was frustrated because I had the match point and it’s very difficult to play a full set more when you’ve just lost a match point.”
Murray has lost all of his last seven meetings against Djokovic and if he is to prevent the world number one from claiming his first title at Roland Garros, he cannot allow the same lapses of concentration he afforded Ferrer.
The 28-year-old enjoyed a dream start, smothering the Spaniard’s second serve and breaking in the first game but the Scot struggled to maintain his level during the early exchanges.
A combination of aggressive returns, inconsistent serving and sloppy errors meant there were only three holds in the first eight games, and while Murray led 3-1 and then 5-3 he was far from his fluent best.
Serving for the set, Murray was broken to love and then the Scot had to save two set points to force a tie-break.
The missed opportunities seemed to destabilise Ferrer, who blasted a simple volley wide to give Murray a 3-0 lead before complaining to photographers about their snapping while he served.
Jolted into life, Murray opened up a 6-1 advantage and while the Spaniard won three in a row to start the nerves jangling, Murray regained composure, dispatching a backhand volley to clinch the opening set.
Ferrer could have hit back early in the second when he led 40-0 on the Murray serve, but again he squandered the chances and allowed Murray to begin his best spell of the match.
Two Ferrer double faults helped the Scot take an instant break himself and a stunning backhand slice, which opened up a 4-1 lead, was just one of several winners as Murray served out for a two-set lead.
The world number three was now in the ascendancy, attacking Ferrer’s second serve at every opportunity and dominating the baseline with more aggression and confidence.
A break in the second game appeared to put Murray on course for victory but his stride was suddenly broken by a limp drop shot as Ferrer broke back for 3-3.
The Spaniard continued to harangue the photographers, and even protested to the umpire, but he kept focus and survived a Murray match point to level at 5-5.
Murray, perhaps stewing over his missed opportunity, handed his opponent a lifeline as a double fault and a netted backhand gave Ferrer a decisive break, which he served out to pull a set back.
The hindrance, however, only seemed to spur Murray on as he clicked into gear in the fourth set, demolishing Ferrer with a number of exhilarating backhands, drop shots and retrievals to race into a 5-0 lead.
Ferrer still would not lie down and he saved two more match points to make Murray serve out, but this time the Scot made no mistake, wrapping up victory in three hours and 16 minutes.