Arturo Vidal had headed Bayern ahead but then wasted a chance to double their lead when he blasted a penalty over the crossbar.
And Ronaldo then twice clinically converted from crosses either side of Javi Martinez’s red card to move to 97 Champions League goals.
Bayern were kept in the game after going down to 10 men by goalkeeper Manuel Neuer, who saved brilliantly from Gareth Bale, Karim Benzema and Ronaldo, BBC reports.
But the Germany international will feel he should have done better for Ronaldo’s winner as the Portuguese stabbed a shot through his legs from close range.
Real may also leave with regrets, as they could have taken a commanding lead into next week’s second leg at the Bernabeu.
As well as Neuer’s string of saves, captain Sergio Ramos had a last-minute header correctly ruled out for offside before Ronaldo lost his footing when seemingly well placed to meet a cross when unmarked four yards out.