Marco Asensio also scored late for Madrid, who advanced 6-3 on aggregate after a 2-1 first leg win in Germany.
Ronaldo's goals, two of which were scored in extra time, enabled the Portugal star to become the first player to reach 100 Champions League goals.
Bayern played with a man down from the 84th minute onward after Arturo Vidal picked up his second yellow card of the night for a foul on Asensio.
After Robert Lewandowski had scored a 53rd-minute penalty for Bayern, an own-goal by Madrid defender Sergio Ramos in the 78th gave the German side a 2-1 lead in normal time - sending the contest into extra time.
The victory puts Madrid into the semi-finals for the seventh straight season and keeps alive their hopes of becoming the first team to defend the Champions League title since the competition's new format was created in 1992.
Los Blancos defeated city rivals Atletico Madrid in the final both in 2014 and 2016.
Bayern, the 2013 Champions league winners, had made it at least to the semi-finals the last five seasons.