A bizarre Sergio Ramos own goal forced the extra period after Robert Lewandowski opened the scoring for Bayern from the penalty spot and Ronaldo equalised.
Marcelo twice cleared off the line for Madrid and Jerome Boateng did the same for Bayern in a thrilling game, which was tilted in Madrid’s favour by Arturo Vidal’s dismissal for two yellow cards, the second of which was harsh.
Ronaldo put Madrid level at 2-2 on the night in the first period of extra time when he scored his 100th Champions League goal, from a clearly offside position, before he wrapped up his treble and Marco Asensio added a fourth.

Ronaldo became the first ever player to net 100 Champions League goals
REUTERSCarlo Ancelotti’s Bayern began well, with Thiago Alcantara's close-range shot brilliantly blocked on the goal line by Marcelo. Arjen Robben lashed the rebound into the side-netting.
Vidal crashed a strike inches over the crossbar and Real goalkeeper Keylor Navas had to be quick off his line to beat Ribery to a through-ball.
Madrid began to find their feet and were soon dominating, with the effervescent Marcelo crossing for Karim Benzema, who headed wide, and Dani Carvajal also firing an effort just off target.
Ramos nearly put the host ahead after the otherwise superb Manuel Neuer spilled a shot, but Boateng somehow blocked his effort on the line to keep his side in the tie.
Toni Kroos fired over and Ronaldo shot when he should have passed to Benzema as Madrid ended the first half looking far more dangerous than their opponent.
However, it was Bayern who took the lead when Casemiro fouled Robben in the area and Lewandowski sent Navas the wrong way from the spot.
Ronaldo levelled the score, heading beyond Neuer in the 76th minute from a fine cross by Casemiro, but Bayern restored overall parity within a minute.
Ramos, so used to being Madrid's hero, turned villain when he shinned the ball into his own net after a scramble in the area.
With the game heading towards extra-time Vidal was sent off for a second booking after appearing to win the ball cleanly from Asensio.
It gave Madrid the upper hand going into the added 30 minutes and they took advantage when Ronaldo scored the crucial second from Ramos's cross, despite being in an offside position.
Madrid added two more late on, leaving Bayern exhausted and angry.
Meanwhile in England, Leicester City's fairytale Champions League journey came to an end at the King Power Stadium when they were held to a 1-1 draw by Atletico Madrid, who reached the semi-finals for the third time in four seasons with a 2-1 aggregate win.
A first-half goal by Saul Niguez proved enough to ease the Spanish side through to the last four despite Leicester’s spirited revival in the second half when Jamie Vardy equalised on the night.
Diego Simeone's side, who won the first leg in Madrid 1-0, had the better of the opening exchanges, but after Leicester finally found their feet, Shinji Okazaki firing over from close range, Saul extended Atletico’s overall lead in the 26th minute, heading home powerfully from Filipe Luis's superb cross.

Leicester City's fairytale run came to an end against a spirited Atletico Madrid side at King Power Stadium. Here, Saul Niguez gives the Madrid side the lead past a diving Kaspel Schmeichel
REUTERSThe Premier League champion, in their first Champions League campaign, responded strongly, dominating the second half, and England striker Vardy equalised on 61 minutes after Ben Chilwell’s shot was blocked, but it was not quite enough.
Leicester defender Christian Fuchs spoke beforehand about the part the home crowd could play and the wall of noise that greeted kickoff would have shaken less battle-proven opposition than Simeone's Atletico.
The hosts were roared forward and had their first real sight of goal when Vardy reached the byline and his cutback looked perfect for Okazaki but his stumbling effort flew high over the crossbar.
Atletico were calm and composed in possession and took the lead with a goal of devastating simplicity.
Luis received the ball wide on the left and his perfect cross was met by a soaring Niguez and his downward header zipped off the turf and beyond the diving Kasper Schmeichel.
Leicester's already difficult task now took on Everest-like proportions as they were required to score three goals against a mean defence, who had leaked only four so far in the competition.
Riyad Mahrez wasted one decent opportunity before halftime but fired straight at Jan Oblak from the edge of the area.
Leicester lived dangerously at the back and Schmeichel did well to deny Yannick Ferreira Carrasco before halftime.
Craig Shakespeare sent Chilwell and Leonardo Ulloa on at halftime and Chilwell was soon in the thick of the action, shooting over the crossbar.
At the other end Antoine Griezmann, scorer of the penalty which separated the sides in Madrid, had Leicester's hearts in their mouths with a surging run into the area but his unselfish pull back was just in front of a tumbling Carrasco.
With half an hour remaining Leicester's lifeline arrived in the form of Vardy when the England striker calmly side-footed past Oblak after Chilwell's shot flew across the area.
Suddenly something extraordinary looked possible.
For the first time in the tie Atletico were rattled and Vardy came close to putting Leicester ahead on the night when his goalbound shot in the 68th minute struck the back of Stefan Savic.
Atletico were now content to start counting down the minutes but Leicester refused to accept their journey was almost over.
At times Simeone appeared to want to join the action on the pitch, such were his energy levels on the touchline, gesticulating wildly and imploring his players to stand firm.
They did just that and as the minutes ticked away so did Leicester's belief in another fairytale.
Leicester 1 (Vardy 61)
Atletico 1 (Niguez 26)
Atletico won 2-1 on aggregateReal 4 (Ronaldo 76, 104, 109, Asensio 112)
Bayern 2 (Lewandowski 53-P, Ramos 77-og)
Real won 6-3 on aggregate after extra time Leading Champions League goal-scorersCristiano Ronaldo -- 101
Lionel Messi -- 94
Raul -- 71
Ruud van Nistelrooy -- 60
Andrei Shevchenko -- 59