After losing the first set Federer took charge of the match
Top seed and defending champion Roger Federer came from a set down to beat Latvia's Ernests Gulbis 3-6 6-1 6-4 and reach the last four of the Madrid Open.
Federer lost to Gulbis in Rome last month and looked in trouble again as he went 3-0 down and had to save three set points before losing the fourth.
But after being broken again at the start of the second set, Federer took charge and powered on to victory.
The Swiss will play Spain's David Ferrer, who beat Andy Murray on Friday.
Federer, the 16-time Grand Slam winner, said the experience of losing last time he played Gulbis, meant he knew he would have his work cut out.
"I was always a bit worried. I got off to a slow start in the first set and paid the price. In the second I recovered and won six games in a row and got on a tear," he said.
"I'm very happy with my performance and very glad to be in the the semis. I didn't have much rhythm in the first set - but I recovered well. I served well and hit the ball very cleanly. I thought it was a good performance even after my poor start."
Earlier, Rafael Nadal secured his place in the last four with a straightforward 6-1 6-3 win over Gael Monfils.
The world number three, who will return to two if he reaches the final, breezed through the first set with breaks of serve in the fourth and sixth games.
Monfils put up more resistance in an erratic second set but his wayward display was summed up by a double fault which sealed Nadal's victory.
"I played my game as well as I could but I was up against the best clay player on the planet and I lost so what can you do," said Monfils afterwards.
The Spaniard, who is seeking a third straight Masters title after wins in Monte Carlo and Rome, faces compatriot Nicolas Almagro in the semi-finals.
The unseeded 24-year-old was on scintillating form in a 6-3 6-1 win over Austrian Juergen Melzer, converting four out of seven break points and not facing a single one on his own serve as he reached his first Masters Series semi.
In the women's competition, fourth seed Venus Williams booked her place in the semi-finals with a 6-3 6-3 win over Australia's Samantha Stosur.
Williams' next opponent will be Israel's Shahar Peer, after she beat 13th seed Li Na 6-4 3-6 6-4 in their quarter-final.
The last quarter-final match saw Aravane Rezai beat seventh seed Jelena Jankovic 7-5 6-4, to earn a semi-final against Lucie Safarova.
The unseeded Czech player reached the last four by recording her first career win over 16th-seed Nadia Petrova, 6-1 1-6 6-4, in their clash.