The holders, attempting to win the competition for the third successive season, struggled defensively but were clinical in attack – and Marcelo and Marco Asensio scored either side of half-time.
Marcelo smashed home a half-volley from the edge of the penalty area to level matters before Asensio capitalised on an error by Rafinha to score a breakaway goal.
Joshua Kimmich had put Bayern in front when he slotted past Keylor Navas at the near post.
The German champions missed a host of chances in an error-strewn encounter, while Real forward Cristiano Ronaldo had a goal ruled out for handball as his run of scoring in every game of this year’s competition ended.
Bayern must now score at least twice at the Bernabeu next Tuesday to prevent Real reaching a fourth final in five years.
Real grind it out again
Real have become specialists at progressing through the European knockout rounds in recent seasons, and this win was a perfect example of their ability to grind out results.
The defensive issues which led to a 3-1 defeat in their dramatic quarter-final second leg against Juventus resurfaced in the first half here, and they could have been further behind before Marcelo scored against the run of play.
Manager Zinedine Zidane made a change at half-time – replacing forward Isco with Asensio – but the game initially continued in the same vein.
However, when Rafinha gave the ball away near the halfway line, Lucas Vazquez and Asensio pounced at pace before the latter calmly lifted the ball home.
Ronaldo was a peripheral figure and did not have a shot on target in the match, the first time he has failed to do so in the Champions League since May 2017.
He did have two efforts – sending a header wide and sending a shot from distance so wildly off target it went out for a throw-in.
Despite that, Real look well placed to reach yet another final.
They may not look as dominant as in the past two seasons, but they remain on course to become the first team since Bayern in 1976 to win a third successive European Cup.
“Real weren’t spectacularly special,” former Chelsea winger Pat Nevin said on BBC Radio 5 live. “They have ridden their luck but Real Madrid somehow find a way to win and you don’t know how they do it.”
A missed opportunity for Bayern
Bayern have lost six games in a row against Real, their worst run against any side in the competition.
Already missing key men Manuel Neuer, David Alaba, Arturo Vidal and Kingsley Coman, they lost winger Arjen Robben and defender Jerome Boateng in the first half.
But they had enough chances to take a commanding lead to the Spanish capital next week, with the usually clinical Robert Lewandowski, Thomas Muller and Frank Ribery missing chances.
Indeed they had a clear opening as early as the first minute, but Lewandowski’s cross from the byeline was too strong for Muller.
Navas should have done better with Kimmich’s opener – he was beaten at the near post from a tight angle – but he saved well from Ribery in the second half.
Soon after Marcelo had equalised, Muller had a powerful volley blocked by Sergio Ramos, and Lewandowski headed straight at Navas when unmarked at a set-piece.
Bayern squandered further chances in the second half – Lewandowski and Muller getting in each other’s way inside the six-yard box, and the former missing the target when in behind Real’s defence in the closing minutes.
There were unsavoury scenes at the final whistle as a small number of fans ran onto the pitch and confronted the Bayern players.
Real’s landmark win – the best stats
*Real have won six consecutive Champions League matches against Bayern, their joint-longest run against an opponent in the competition’s history, also winning six in a row against Ajax between 2010 and 2012.
*The past three occasions on which Bayern have scored first in a Champions League match and lost have been against Real (also both quarter-final legs last season).
*This was Real’s 150th Champions League win, making them the first team to reach the milestone.
*Asensio’s past three Champions League goals have been as a substitute, with all in knockout matches – two against Bayern (last season’s quarter-final and this match) and one against Juventus in last season’s final.
*No player has been involved in more goals for Bayern in the Champions League this season than Kimmich (three goals and three assists).
*Kimmich’s goal was the 100th goal scored under Jupp Heynckes in the Champions League (22 for Real Madrid, 78 for Bayern).
*Marcelo has scored three goals in his past five Champions League appearances – as many as in his previous 53 appearances in the competition combined.
*Vazquez has assisted 12 goals in all competitions this season – among La Liga players, only Lionel Messi (18) has assisted more.>