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.
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. - BBC -