MADRID, Spain -- Rafael Nadal fought back to beat David Ferrer 4-6, 7-6 (3), 6-0 in Friday's quarterfinals of the Madrid Open, maintaining his bid to reach a seventh straight final since returning from a knee injury.

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 an early exit like Novak Djokovic and Roger Federer earlier this week.

"I think (I) have to be very happy for making it to the semifinals, and even more so after how the match has gone," said Nadal, who won in 2005 and 2010. "I could have been very close to thinking about the next tournament right now."

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.

Nadal has won four titles this year since being sidelined for several months with tendinitis in his left knee. Even though he has said his leg still bothers him, Nadal failed to use it as an excuse.

"David is a fantastic player," he said. "When you play up and down against players like David, you know, it's very difficult to win."

Nadal will play 113th-ranked Pablo Andujar of Spain, who ousted Kei Nishikori 6-3, 7-5 the day after the Japanese player upset Federer.

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 an 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.

"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 after the Serb dispatched Angelique Kerber 6-3, 6-1.

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."