Referee Howard Webb had a torrid time, showing nine yellow cards, and had to deal with penalty claims, high tackles, flare-ups, baying Bayern fans, theatrics and continual protesting over his decisions.
The only surprise was that nobody was sent off, not even Real substitute Marcelo who produced a scything tackle on Thomas Muller in stoppage time.
There was also pulsating football amid the chaos as Franck Ribery fired Bayern ahead in the 17th minute and Mesut Ozil levelled with a soft equaliser early in the second half.
Gomez then snatched the winner, his 12th goal of the Champions League and 40th of the season, shortly after having a penalty appeal turned down, to hand Real their first defeat of the Champions League campaign.
"I want to give a great compliment to my team my players, that they played so well and ran so much and played so well," said Bayern coach Jupp Heyckes, who led Real to their sixth European Cup title in 1998.
The Bavarians, whose season hinges on them reaching the final in their own Allianz Arena, managed to keep Cristiano Ronaldo under wraps for most of the game, although he laid on Real's goal.
"A draw would have been a fairer result but this is football, whoever scores wins and the game ends when it ends," said unflustered Real coach Jose Mourinho.
"It's not a terrible result. It's not as if we need an historic comeback with crazy numbers in the second leg, we need a normal result, 1-0 or 2-0, which we are capable of getting with our supporters behind us."
The two swaggering clubs, paired for the tenth time in Europe's top competition, have been European champions 13 times between them and previous meetings have been filled with unsavoury incidents.
This meeting did not plunge those depths but, with Real having made an art form out of gamesmanship under Mourinho's leadership, there was always likely to be trouble.
The first trouble came when Fabio Coentrao clipped Arjen Robben and 10 players immediately surrounded the referee to remonstrate.
Ribery was jostled by Real players after going down in the penalty area, Robben took a kick at Ronaldo after the ball and the Dutchman was then booked for a high kick on Coentrao.
There were numerous other incidents and Real picked up a series of yellow cards in the second half for late challenges, often producing theatrical reactions from their opponents.
Bayern took the lead when Ribery fired home from near the penalty spot after the La Liga leaders failed to clear a corner, Mourinho later claiming that a Real player was offside.
Bayern largely managed to cut off the supply to the prolific Ronaldo.
The Portuguese forward responded with his usual shimmies and stepovers but his first half efforts were restricted to two wasted free-kicks and a shot over the bar.
His curled his first free-kick over the wall but missed the target and sent his second into the defensive wall, then demanded a penalty for handball.
Bayern, meanwhile, could easily have had a second.
Real were in trouble at the back, repeatedly exposed down the flanks, and a Bastian Schweinsteiger shot flashed wide of their goal from 25 metres.
In the run-up to half-time, Toni Kroos carried the ball from his own half and slipped it to Gomez, whose left-foot shot was superbly turned away by Iker Casillas. Then Kroos fired a free-kick straight into the wall.
Bayern started the second half brightly with Robben cutting inside and firing over the bar from just outside the area.
But some dreadful defending by the Bavarians allowed Real to equalise in the next move.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.