Arturo Vidal headed Bayern into a first-half lead, but then skied a penalty attempt on the stroke of half-time before Ronaldo volleyed the defending champions’ level.
Bayern played the last half an hour a man down after centre-back Javi Martinez was sent off for two fouls on Ronaldo within three minutes of each other.
Four-time world player of the year Ronaldo then slotted in the winner between goalkeeper Manuel Neuer’s legs for the winner 13 minutes from time.
“We believe we can still do it, we were the better team in the first half, could have made it 2-0 or 3-0,“ Neuer told ZDF.
But Bayern were outplayed in the second-half and most of Real’s 23 shots on goal came after the break.
We had everything under control in the first half, but didn’t use the room consistently, said captain Philipp Lahm. "The tipping point was the red card."