It was Ronaldo's 11th consecutive goal in the Champions League and a dramatic finale to a pulsating game at the Santiago Bernabeu.
Madrid started the match in a seemingly impregnable position having won the first leg 3-0 in Turin.
But a brace in the first-half from Mario Mandzukic reduced the deficit to 3-2. Blaise Matuidi's goal midway through the second-half levelled the tie on aggregate.
But in the seventh minute of stoppage time, referee Michael Oliver judged Mehdi Benatia's challenge on Lucas Vazquez to be a foul and pointed to the spot.
The Juventus goalkeeper Gianluigi Buffon was sent off for arguing with Oliver over the decision. Striker Gonzalo Higuain was sacrificed to make way for Szczesny.
"This referee has no heart, he has a garbage bag instead of a heart," Bufffon told Italian channel Mediaset Premium. "If you do not have personality and courage, you should go to the stands to watch the match with your wife and a Sprite."
"I do not understand why they protest against the penalty," Ronaldo told beIN Sports. "If he did not commit the foul, Lucas would have scored. During the game, Benatia and the rest of them had already been kicking us from behind. But we are happy and we are in the semi-finals."
Madrid coach Zinedine Zidane was more sympathetic towards the veteran keeper who has featured in 125 Champions League matches.
"He did not deserve to be sent off," Zidane said. "But we cannot change it. It will not take away from everything he has done, even if it's a shame to end his Champions League career this way."
"It leaves a bitter taste," Juventus coach Massimiliano Allegri added: "Because we have not had the chance to take the game to extra-time. In view of the two legs both teams would have deserved to move on to the next phase."
Madrid, who have won the trophy two years on the trot, join Bayern Munich, who knocked out Sevilla, Liverpool and Roma in Friday's semi-final draw.