Jhon Cordoba fired an 86th-minute winner as Mainz claimed a shock 2-1 victory to end Bayern Munich's perfect home record this season and potentially breathe new life into the Bundesliga title race.
Borussia Dortmund's 2-0 win at Darmstadt means Bayern travel to Signal Iduna Park on Saturday with the lead over their nearest rivals cut to five points.
Franck Ribery's first Bundesliga start in more than a year following an injury ordeal came as former Bayern president Uli Hoeness sat in the stands in the week of his release from prison, but the defending champions were far from their usual levels of creative brilliance.
Bayern struggled for clear-cut chances throughout and required a long-range strike from Arjen Robben in the 64th-minute to cancel out Jairo Samperio's first-half opener for the visitors.
Pep Guardiola sent on Thomas Muller and Kingsley Coman in pursuit of the win, but it was Cordoba, who was also on target in Sunday's impressive 3-1 win over Bayer Leverkusen, who had the final word to lift Martin Schmidt's Champions League hopefuls up to fifth.
Mainz defender Alexander Hack headed over from Fabian Frei's fifth-minute set-piece, as Bayern settled quickly into their customary dominance of possession.
Ribery floated a left-wing cross towards the edge of the area where Arturo Vidal's superb volley drew an equally impressive save from Loris Karius.
The Mainz goalkeeper settled in for a busy evening by then denying Juan Bernat and seeing his defenders scramble the rebound clear with Robert Lewandowski lurking.
But the visitors overcame that flurry of pressure to take a 26th-minute lead on the counter-attack.
The ball broke to the right following an aerial challenge between Christian Clemens and Bernat, leaving Giulio Donati to cut a low cross behind Yunus Malli that the on-rushing Jairo finished crisply at the back post.
Robben cut in from the right to whip a left-footed shot past the far post, but Mainz preserved their advantage to half-time in relative comfort.
Six minutes into the second half, Clemens slashed wastefully wide when afforded space in the Bayern box – Guardiola's men once again showing themselves to be susceptible on the break.
Karius kept out Vidal's latest attempt from range and Medhi Benatia, like Ribery featuring in a starting line-up for the first time since December's Champions League win at Dinamo Zagreb, headed off target as Bayern continued to be restricted to half-chances.
Indeed, there appeared to be little on when Robben collected the ball 30 yards from goal and took aim to arrow a low drive beyond Karius.
That setback did not distract Schmidt's diligent side from their task and, having repelled Bayern's sustained but blunt pressure, Cordoba stunned the Allianz Arena in the closing stages.
It was another nicely worked goal, with the substitute collecting Julian Baumgartlinger's pass to beat Manuel Neuer and end Bayern's home victory streak at 15 in all competitions this term.
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.