You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
Leading 2-1 in the second set of his quarterfinal against the Spaniard, Djokovic lurched awkwardly when chasing a ball to defend a break point, and grimaced in pain as he clutched his left leg.
Walking gingerly between points but still in full flight during play, the world number one survived a pulsating second set and stunned Ferrer by taking an early break in the third.
The fifth seed doggedly chased down everything thrown at him but was powerless to stop Djokovic's charge as the Serbian found his range in devastating form to seal the last set in 30 minutes with an ace.
Djokovic played down his physical troubles and said he would be fully fit to meet Murray for Friday's semi-final.
"Luckily for me it wasn't something that stayed there for long time. It was just a sudden pain.
"It's just today I found it very difficult after a long time to breathe because I felt the whole day my nose was closed a little bit. I just wasn't able to get enough oxygen.
"But at this stage of the tournament, when you're playing somebody like David, somebody that... makes you play over five to 10 shots in the rally, your physical strength and endurance comes into question.
"I'm really fit and I have no concerns of recovering for the next match."
Scotsman Murray earlier romped to a straight sets victory over Kei Nishikori in a little over two hours.
While the scoreline may have suggested otherwise, Djokovic spent two hours and 44 minutes out on court, with much of it consumed in epic, attritional rallies.
If Murray opted to follow proceedings on TV, he might have sympathised with Djokovic, having been put through a similar, if longer, ordeal in a four-set semi-final against Ferrer last year.
That was prelude to a straight sets trouncing by Djokovic in the final in which the Briton appeared sapped from the toil of a long tournament.
While Murray was back in his hotel room, a steely-eyed Ivan Lendl, the Briton's new coach, sat court-side taking notes and would have been pleased with the way Ferrer pushed Djokovic hard in a fiery opening set.
Djokovic struck the first blow with a ripping forehand winner to seal a break in the fifth game, and saved a break point soon after following a frenetic 34-hit rally.
A booming inside-out forehand sealed the first set for the Serbian and he raced to 2-0 in the second before suffering the leg troubles.
Ferrer broke back to lead 3-2, but crumbled with an unforced error to blow a chance to break Djokovic again and watched in horror as the struggling Serbian blasted two forehand winners from the baseline to close out the game.
Djokovic found a second wind to trade service breaks with Ferrer before the Spaniard surrendered the tiebreak with a mis-hit forehand that sailed well past the baseline.
With the finish-line in sight, Djokovic unleashed a searing forehand winner that kissed the line to secure an early break before blasting two aces when serving for the match.
Looking ahead to his clash with fellow 24-year-old Murray, Djokovic said: "Our friendship and rivalry, you can call it, goes a long time back ... Goes (back) to when we were 12 in France, (our) first tournament. We played a lot of junior events together.
"It's great to see that somebody who you grow up next to is doing well. This is going to be another great challenge for both of us," added the Serb, who holds a 6-4 record over Murray.