Mario Gomez's last-minute goal gave Bayern Munich the advantage over Real Madrid after the first leg of their Champions League semi-final.
Franck Ribery's powerful finish had given the hosts the lead.
But Mesut Ozil's close-range effort just after the break looked to have earned the visitors a draw.
Gomez wasted a string of second-half opportunities but touched in from just a couple of yards out to give the German side a deserved lead.
Did you know?
Real Madrid coach Jose Mourinho is trying to become the first manager to win the European Cup/Champions League with three different teams
Real had seemed content to sit on their draw after spending most of the evening on the back foot and they looked set to return to Spain on level terms, with Gomez proving wasteful in front of goal despite causing centre-backs Pepe and Sergio Ramos problems all night.
But, with Cristiano Ronaldo producing an ineffective performance for the visitors, Gomez showed composure when it mattered to take his last chance to score his 40th goal of the season.
As well as facing a deficit, Madrid coach Jose Mourinho's plans for the second leg will be complicated by the fact that Real, who are four points clear of Barcelona in La Liga, travel to the Nou Camp on Saturday, while Bayern can rest players at Werder Bremen after their hopes of winning the Bundesliga were all but ended last weekend.
But Jupp Heynckes's side were certainly worth their win as they look to become the first team to contest a Champions League final at their own stadium.
Before Bayern took the lead their goalkeeper Manuel Neuer was called into action to tip away Karim Benzema's effort and Ribery went down under a Ramos challenge in the area.
A Toni Kroos corner thumped against the chest of Ramos and Ribery was the first to react, steering a low shot through a crowd of bodies and past visiting goalkeeper Iker Casillas.
Bayern continued to stretch the Real defence in wide areas and, after slicing well over with one shot, Ronaldo's impact was limited to a couple of free-kicks that failed to trouble Neuer.
Ramos and Pepe never looked comfortable in dealing with Gomez and the Bayern striker had a firm effort pushed away by Casillas just before the interval following an incisive break from the hosts.
But, seven minutes after the restart, Real pulled level after Ronaldo saw a weak effort easily pushed away by Neuer.
Ronaldo's quiet night
Cristiano Ronaldo failed to score for just the fourth time in 17 matches. It is a run of games that has still brought 22 goals.
Ozil reacted quickly to feed Benzema and the Frenchman's drilled cross was pulled back by Ronaldo for Ozil to touch in from just a couple of yards out.
Casillas was out quickly to produce a brave block after Gomez was played through by Robben.
Gomez had no excuse for lifting over from just four yards after Ramos again failed to deal with a set-piece from Kroos and the Germany striker also glanced over with two headers from good positions.
But he finally made the breakthrough when Philipp Lahm's cross from the right thumped in off the striker at the near post.
Bayern Munich coach Jupp Heynckes: "My players showed what I had demanded from them - lust and hunger for success.
"I think we more than deserved the win because we played cleverly and intelligently."
Real Madrid manager Jose Mourinho:
"The second goal came out of context. We were a better team in the first half in the second half the game was a bit broken and I didn't like it so much.
"It was under control by both teams and no-one believed they could win 2-1 but that's football they scored and we have to play in the second leg at home in a different atmosphere and let's go for it.
"I prefer to (a game like Barcelona at the weekend) it than not have it like Bayern. They are eight or nine points behind Dortmund. For us it means a lot but we are fighting for a title. We know it's a disadvantage but it's better like this." - BBC Sport