Bayern Munich midfielder Arturo Vidal’s harsh 84th-minute dismissal was the first pivotal moment of a thrilling game, and then Ronaldo was clearly standing in an offside position to score Madrid’s second in extra time.
Needing at least two goals to progress, Bayern had led when Robert Lewandowski confidently drilled in a penalty.
Madrid struggled to find rhythm at a nervy Bernabeu before Ronaldo headed in Casemiro’s precise cross.
Bayern responded just 36 seconds later as Sergio Ramos’ own goal forced extra time, but then crumbled after Ronaldo illegally fired in Madrid’s second.
The Portugal captain tapped in the third – for his 100th Champions League goal – after Marcelo’s marauding run, with Marco Asensio sealing victory by firing into the bottom corner.
Madrid will discover their semi-final opponents when the draw is made on Friday.
Neighbours Atletico Madrid progressed after edging past Leicester City, while the other two ties – Barcelona against Juventus, and Monaco against Borussia Dortmund – take place on Wednesday.
Bayern see red in controversial exit
Anticipation was high when two of Europe’s biggest and most successful clubs were drawn together – and an enthralling tie did not disappoint.
However, it was somewhat tinged by Madrid benefitting from two debatable decisions by Hungarian referee Viktor Kassai and his officials.
Chile midfielder Vidal, already booked for an early foul on the edge of the Bayern area, was shown a second yellow card for what appeared to be a clean sliding tackle on Madrid substitute Asensio.
And then Ronaldo was standing at least a yard offside when he met Ramos’ pass and spun to fire Madrid 4-3 ahead on aggregate.
“In a quarter-final you have to put a better referee, or it is the moment to introduce video refereeing, which is what Uefa are trying, because there are too many errors,” Bayern manager Carlo Ancelotti said.
Nothing separated the two teams over 180 engaging minutes in Munich and Madrid, only for the German champions to finally run out of steam as they battled a numerical disadvantage.
Bayern also played the final 30 minutes at the Allianz Arena last week with 10 men after Javi Martinez’s dismissal.
Ancelotti’s side remained resolute in the first period of extra time – until the tiring visitors unravelled after Ronaldo put the Spanish league leaders ahead.
History-seeking Madrid get the rub of the green
Madrid are aiming to become the first club to retain the Champions League and moved a step closer by eventually seeing off Bayern.
For long periods, Madrid were edgy defensively and uncertain going forward – with Ronaldo guilty of wasting a number of chances in normal time.
Bayern knew they would have to become only the third side to overturn a first-leg home defeat in a Champions League tie to reach their sixth successive semi-final.
Fewer places are harder to achieve that than the home of the 11-time European champions.
Although only one away team had managed to leave the Bernabeu with victory in Madrid’s previous 33 home matches in all competitions, Bayern looked confident and organised as they quietened the home crowd.
Bayern top scorer Lewandowski, who missed the first leg with a shoulder injury, fired them ahead with a coolly taken penalty before Ramos’ bizarre own goal – the ball ricocheting off his shin and spinning inside the near post – forced extra time.
But Madrid eventually wrestled control of the tie thanks to their numerical advantage and the decisions of the officials.
Sheer relief greeted the final two Madrid goals as their jubilant players wildly celebrated reaching a record seventh successive semi-final in Europe’s premier club competition.
“I don’t get involved if decisions are right or wrong,” said.
“Everyone has their own opinions, some might say it was not a second yellow card for Vidal, some might say it is.
“Cristiano’s goal might have been offside but it doesn’t change anything.”
‘Ronaldo is always there for us’ – post-match reaction
Madrid manager Zinedine Zidane:
On some home supporters whistling at Cristiano Ronaldo during the game: “Cristiano has shown that in the key moments he is there, he makes the difference. When he has to be, he is there.
“It is unique and we are happy for him and for the team.
“Maybe after today they do not whistle anymore, but this is Madrid and that things happen from time to time, and he knows it. He has to be calm.
“The public will always thank Cristiano for everything he has done.”
- Cristiano Ronaldo’s hat-trick made him the first player to reach 100 Champions League goals
- On the same night, Real’s neighbours Atletico reached the same tally as a club
- Madrid have qualified for the Champions League semi-finals for the seventh consecutive season – the longest streak in competition history
- Bayern lost both legs of a Champions League knockout tie for the first time since April 2014, which was also against Real Madrid in a 5-0 semi-final aggregate defeat
- Ronaldo has scored nine times against Bayern in the Champions League – only Barcelona’s Lionel Messi has scored as many against a single opponent (against Arsenal)
- Lewandowski has netted six goals against Real Madrid in the Champions League, the most of any opposition player
- The Poland striker converted his sixth penalty in the Champions League, maintaining his 100% record from the spot in the competition (excl. shootouts)
- Arturo Vidal’s red card was the 19th shown to a Bayern Munich player in the Champions League – only Juventus (22) have had more in the competition
- The average age of Bayern’s starting line-up in this game was 30 years and 116 days, making it their oldest in Champions League history