Dominic Thiem beat Roger Federer in the Indian Wells final in March
Dominic Thiem saved match points to end Roger Federer's clay-court return and reach the Madrid Open semi-finals.
Swiss Federer saved match points in his quarter-final on Thursday but squandered two of his own in the second-set tie-break against Thiem.
Austria's Thiem eventually came through 3-6 7-6 (13-11) 6-4 to set up a meeting with world number one Novak Djokovic.
Fifth seed Thiem previously beat 20-time Grand Slam champion Federer in the Indian Wells final in March.
Fourth seed Federer, 37, was playing in his first clay-court tournament for three years.
Thiem, a predominantly clay-court player who lost to Rafael Nadal in last year's French Open final, recovered from a slow start against Federer.
He created five break points on the Federer serve in the second set, but the Swiss held to force an eventual tie-break.
Federer had match point at 8-7 and 10-9 in the tie-break but Thiem saved them both and won four of the final five points to ensure a deciding set.
Thiem broke Federer early and went on to serve out the match at the second attempt.
He will play Djokovic on Saturday after the Serb received a walkover to the semi-finals.
Djokovic had been set to face Marin Cilic but the Croat pulled out after suffering with food poisoning.