The result shakes up the title race ahead of Saturday's crunch clash when Pep Guardiola's Bayern play at second-placed Borussia Dortmund.
Colombia striker Jhon Cordoba came off the bench to seal only Mainz’s second victory in Munich with the winner on 86 minutes to finish off a counter-attack.
“We had our chances and then let them counter-attack. We shouldn’t have allowed that to happen,” fumed Bayern’s goal-scorer Arjen Robben.
Mainz took a shock lead at the Allianz Arena when Spanish winger Jairo fired home in the first-half with the Bayern defence well beaten.
Robben pulled a goal back for the Bavarian side on 64 minutes.
Despite Mainz managing only 22 per cent of possession, Cordoba grabbed the late winner and was mobbed by his teammates.
“We knew how we could win here with a strong defensive display and a good counter-attack,” said Mainz coach Martin Schmidt, who praised his side’s ‘outstanding display’. “It feels really good.”
Dortmund’s 2-0 win at Darmstadt on Wednesday cut Bayern’s lead from eight points to five as another Colombia striker, Adrian Ramos, and defender Erik Durm netted.
“We and Bayern both know that things can now be a bit tight. We want to win the thing,” said Dortmund’s Germany defender Durm.
Hertha Berlin cemented third place, but remain 15 points adrift of Dortmund, with a 2-0 win over Eintracht Frankfurt in the capital.
Salomon Kalou and Mitchell Weiser scored to keep Berlin on course for a first return to the Champions League since 2000.
At the other end of the table, Werder Bremen climbed out of the relegation places with a shock 4-1 win at Bayer Leverkusen as veteran Claudio Pizarro claimed a hat-trick.
The 37-year-old Peru international showed why he is the Bundesliga’s top scoring foreigner by needing just under half an hour to wrap up his hat-trick which included a penalty.
Having knocked Leverkusen out of the DFB-Pokal (German Cup) in the quarter-finals last month, Bremen again humbled Leverkusen.
Roger Schmidt’s Leverkusen have now lost four of their last five games in all competitions and drop to seventh in the league.
Elsewhere Schalke climbed to sixth with a 3-2 comeback win at home to Hamburg while Borussia Monchengladbach remain fourth after their 4-0 thrashing at home to Stuttgart.
Second-from-bottom Hoffenheim boosted their survival chances with a 2-1 win over Augsburg.
On Tuesday, Germany winger Andre Schurrle claimed the first Bundesliga hat-trick of his career as Wolfsburg routed bottom side Hannover 4-0 away.
March 1 is a lucky day for Schuerrle who also scored a hat-trick for ex-club Chelsea against Fulham in the Premier League exactly two years ago.
His performance will boost his standing at Wolfsburg and in this one game he has scored more goals than in his previous 33 matches for the Champions League side.
He needed just 26 minutes to score three goals before Germany teammate Julian Draxler added Wolfsburg’s fourth at Hannover’s HDI Arena.
The win leaves Wolfsburg eighth while Hannover are bottom, four points from their nearest rival and seven points from safety.
The German FA (DFB) is expected to fine both clubs after one of the flares fired from the away fan block hit the Hannover bench before kick-off, but no-one was hurt.
Elsewhere, French striker Anthony Modeste rescued a point for Cologne in their 1-1 draw at Ingolstadt after forward Lukas Hinterseer had given the hosts the lead.
Follow us on Twitter @NatSportUAE
Like us on Facebook at facebook.com/TheNationalSport