Franck Ribéry had given the German side a first-half lead but the visitors improved either side of the break and equalised early in the second period through Mesut Özil. However, Gomez's 12th goal in this season's competition in the final minute ensured it is Bayern who will go into next Wednesday's second leg at the Santiago Bernabéu confident of returning to their home ground for the final on 19 May.

Even before kick-off the home fans had made it abundantly clear how much the game meant and their vociferous support helped Bayern to settle early on with some encouraging spells of possession. Madrid's experience in high-profile situations meant they were not about to be intimidated, however, and it was the visitors who created the first chance when Özil fed Karim Benzema, whose fierce strike from the right was palmed over by Manuel Neuer.

An ominous silence gripped the Munich crowd as the Liga leaders grew in confidence, but their fear turned to elation on 17 minutes as Ribéry slammed in the opener with a low shot after Madrid had failed to deal with Toni Kroos' left-wing corner. The goal visibly calmed Jupp Heynckes' side and though Cristiano Ronaldo went close with a trademark free-kick shortly afterwards, it was the Bavarian club in the ascendancy heading towards the interval.

Bastian Schweinsteiger fired narrowly wide from range and Gomez had a powerful first-time effort with his left foot tipped over by Iker Casillas. As Benzema warned when he tested Neuer after cutting in from the right between times, Madrid's threat was far from extinguished.

Any lapses were likely to be punished and following a bright start to the second period, Madrid capitalised on a misjudged clearance by David Alaba to outnumber the Bayern defence. Neuer did well to deny Ronaldo in the first instance, but Madrid retrieved the loose ball and, though Benzema scuffed his shot across the face of goal, it fell kindly for Ronaldo to turn back inside and Özil duly levelled from close range.

Initially Bayern looked ruffled but soon regained their composure and set about restoring their lead. Having been kept quiet for most of proceedings, top scorer Gomez began to impose himself on the game. The striker blazed a glorious opportunity over the bar after another Kroos set piece had caused problems in the visiting defence, before heading a Philipp Lahm cross narrowly too high.

The combination threatened once more in the latter stages as Lahm again set up for Gomez to head into Casillas' arms with five minutes remaining. The Madrid goalkeeper was eventually beaten again in the final moments as Gomez slid in to convert yet another Lahm delivery and edge the Bundesliga giants a step closer to that dream home final.

The UEFA word, the UEFA logo and all marks related to UEFA competitions, are protected by trademarks and/or copyright of UEFA. No use for commercial purposes may be made of such trademarks. Use of UEFA.com signifies your agreement to the Terms and Conditions and Privacy Policy.