Ronaldo’s coolly taken 97th-minute penalty into the top corner came after Medhi Benatia brought down Lucas Vazquez in the box.
Juve goalkeeper Gianluigi Buffon, in what might be his last Champions League appearance, was sent off by English referee Michael Oliver after awarding the spot-kick, for foul and abusive language.
Real, Champions League winners in three of the past four seasons, came into the second leg leading 3-0, helped by Ronaldo’s stunning bicycle kick.
But the Serie A leaders got off to a perfect start when Mario Mandzukic headed in from Sami Khedira’s cross after just two minutes and Mandzukic got a second before half-time.
Blaise Matuidi pounced to capitalise on Keylor Navas’ fumble to level the tie on aggregate before the dramatic ending.
Real join Liverpool, Roma and Bayern Munich in the last-four draw, which takes place in Nyon on Friday at 12:00 BST.