The German striker had plenty of attempts on goal throughout the contest and finally came up with a winner in the 90th minute to allow the Bundesliga giants to take a slight lead into next Wednesday's return leg at the Santiago Bernabeu.
Franck Ribery opened the scoring for the home side when he fired home from just outside the six-yard box after Sergio Ramos failed to properly clear a corner in the 17th minute, further lifting the Bayern supporters who were already full of voice.
Real were looking dangerous as they worked their way further into the match and managed to grab a leveler less than ten minutes into the second half when Germany international Mesut Ozil tapped home from close range. The goal came about in quite incredible circumstances as Cristiano Ronaldo's one-on-one attempt was kept out by Manuel Neuer before Karim Benzema picked up the scraps and fired a scuffed shot across goal which Ronaldo knocked into the path of Ozil to stab home.
Jose Mourinho's side looked content to sit back as the minutes ticked by, protecting their away goal rather than setting up any attack, and it came back to bite them when Bayern grabbed the winner. Skipper Philipp Lahm skinned Fabio Coentrao down the right before cutting back for Gomez whose first touch deflected straight back off his left knee and in past Iker Casillas for his 12th Champions League goal of the campaign.
Both keepers had enough to do throughout with Neuer on hand to brilliantly deny Benzema in the seventh minute before Casillas came up with a top shelf save of his own when Gomez struck on target from an angle late in the opening 45 minutes.
Chances were harder to come by in the second term but Gomez should really have done better when he stabbed a pointblank opportunity over the bar with 20 minutes remaining, however, in the end he was able to get the important one on target.
There were huge shouts for a red card in injury time when the hot-headed Marcelo lashed out at Thomas Muller with a horrendous challenge from behind but referee Howard Webb only produced a caution much to the dismay of the German side.
Nevertheless, the one-goal triumph was enough for Jupp Heynckes and his men to rejoice with a huge victory over their more fancied rivals, setting up a very interesting return leg in Spain's capital next week.
UEFA Champions League semi-final - first leg
Allianz Arena, Munich - 66,000