In a meeting of Spain's top ranked players, Ferrer's baseline game on the red clay almost proved too much for the fifth-seeded Nadal.
But Nadal held on to force a third set and won six straight games to improve his career record against Ferrer to 18-4, avoiding making an early exit like Novak Djokovic and Roger Federer earlier this week.
"I'm just happy to be back in the semifinals at Madrid," said Nadal, who won in 2005 and 2010.
Nadal will play either Pablo Andujar or Kei Nishikori of Japan.
The Spaniard has won four titles this year since being sidelined for several months with tendinitis in his left knee.
In the women's event, top-ranked Serena Williams struggled past Anabel Medina Garrigues 6-3, 0-6, 7-5, and second-seeded Maria Sharapova joined her in the semifinals after easing by Kaia Kanepi of Estonia 6-2, 6-4.
The fourth-seeded Ferrer's ability to keep points alive with error-free long rallies gave him an early lead. He used his speed to break twice in the second set, sealing both with approach shots at the net for a 4-2 advantage.
Nadal then dug in and broke twice to win the next three games.
Ferrer had a golden opportunity to earn two match points when leading 5-4 and 30-15. He had plenty of time to slam a floating ball into an open court but instead fired at his opponent's feet, allowing Nadal to scoop it over the net.
"It was a tightly contested match," Nadal said. "David deserved it more than I did to reach the semifinals, but that is sport. I was lucky to somehow save that ball down 15-30.
Errani, Ivanovic win
"After missing his chance David fell apart a little. He lowered his intensity in the third set and I didn't have to do as much."
Nadal was steadier in his shot-making to level in the tiebreaker, and he only got better in the third set. After placing a perfect lob near the baselines, he wowed the Caja Magica crowd by nailing a forehand winner while almost stumbling to the ground en route to building an insurmountable 4-0 lead.
Sharapova will play Ana Ivanovic in a battle of former No. 1s after the Serb dispatched Angelique Kerber 6-3, 6-1.
Williams will face Sara Errani of Italy, who downed Ekaterina Makarova 6-4, 6-3.
Williams appeared to be worn down after being blanked in the second set and falling behind 4-2 in the decider. But the defending champion rallied to break the Spaniard's serve twice.
"I just wasn't really into it, my feet weren't moving," Williams said of the second set. "To change it I got up early [before the third set] and did some high knees, some stretching, anything I could to get my intensity back up to where it needs to be."Suggest a correction