Cristiano Ronaldo's 98th-minute penalty sent the hosts through after Juventus had scored three to level on aggregate.
Article top media content
An error occurred while playing the video
Cristiano Ronaldo's last-gasp penalty on his 150th UEFA Champions League appearance sent Real Madrid through to their eighth consecutive semi-final.
Juventus needed an early fillip having been defeated 3-0 at home in the first leg and it arrived inside two minutes when Sami Khedira darted down the right channel and crossed for Mario Mandžukić to thump a header past Keylor Navas.
The Croatian striker repeated the trick from Stephan Lichtsteiner's centre before the interval and the most unlikely of turnarounds became a serious reality when Blaise Matuidi stabbed in the third following a Navas fumble just past the hour.
But, with extra time looming, Medhi Benatia barged over Lucas Vázquez and Ronaldo kept his cool to fire the penalty into the top corner past Wojciech Szczęsny – who came on for the spot kick after Gianluigi Buffon was dismissed.
Key player: Mario Mandžukić (Juventus)
Mandžukić had not been at his best and was competing with Juan Cuadrado for a place in the starting XI. Allegri, however, opted for the tall striker and his decision paid huge dividends as the Croatian gave the Bianconeri hope with two great headers in the first half. His work ethic and commitment represents the spirit of this Juve side.
Reporter talking points
Joseph Walker, Real Madrid: What's the Spanish for 'out of jail?' Somehow, Madrid are through. Second best all night, Allegri had Zidane's number tactically yet dramatic late circumstances, as is their wont in this competition, see Madrid through. The Bernabéu rose as one to applaud both teams off. What a game!
Paolo Menicucci, Juventus: Juve needed a miracle after the 3-0 home defeat in the first leg and they went as close as it gets to creating one. Despite the elimination, the Bianconeri showed the world their amazing character. It was a very sad ending, especially with the Buffon sending-off. The added-time penalty was a terrible blow but I'm sure they will be back to compete at the very highest level next season with this spirit. The (almost) perfect game was not enough for them.
- Ronaldo's tenth goal against Juventus, a #UCL record against a single club
- Ronaldo has scored in 11 #UCL games in a row
- Madrid had not been two down at half-time in a #UCL home game since February 2000
- Mandžukić first visiting player to score two first-half #UCL goals at Santiago Bernabéu