The Spaniard had surpassed John McEnroe's record for 50 straight-set wins on a single surface when he eased through to the last eight of the event on Thursday.
But that remarkable streak was brought to a close as Nadal surrendered the opener, and Thiem refused to let the momentum slip as he delivered a stirring second-set showing to win 7-5 6-3.
Coincidentally, it was Thiem who last beat Nadal on clay, at last year's Rome Masters, shortly before the Spaniard rampaged to a 10th French Open title without dropping a set.
Federer will therefore move back to the top of the rankings, despite taking the clay-court season off, but of more effect is a performance from Thiem that suggests Nadal may have a genuine rival at the French Open.
'I mean, there is a reason why I did my first Masters finals here a year ago.
Serving at 6-5, Thiem wrapped up the set with an ace and then clutched his fist, aware that winning one set against Nadal on Madrid's clay was in itself a significant breakthrough.
But Nadal chose to take positive out of his defeat as he believes he would place himself in a good position ahead of the season-ending ATP Finals. "Whenever he plays really well, it's very hard to stop him", Nadal said. "I had to go for shots and go down the line and everything worked today". We're not playing a game where the differences are big or massive. It's great to play here for me.
But that incredible run was ended as the 31-year-old surrendered the opener and Thiem delivered a nerveless second-set showing to triumph in style.
Idea, Airtel stocks feel heat from Jio's ISD plan
The new post-paid Rs 199 plan announced by Reliance Jio is expected to hit revenue of competitors marginally and may trigger tariff war in the segment, according to market analysts.
'Like this I should go in every match against him.
"It takes a really good match to beat Rafa on clay".
Shapovalov, 19, ranked at 43 in the world, fired 29 winners past Edmund, a surprise semi-finalist at the Australian Open in January.
Shapovalov, who reached the semis at the 2017 Rogers Cup, is hopeful his run will continue.
Alexander Zverev upped his win streak to seven after gaining revenge on John Isner 6-4, 7-5.