Despite claiming the three points, the current German champions were denied the opportunity to lift their 24th league title as rivals Schalke 04 and Borussia both recorded wins.
Bastian Schweinsteiger broke the deadlock with just eight minutes remaining as he headed home substitute Mario Gotze's delightful cross.
Creator Gotze turned goalscorer six minutes later when he sealed the game with a simple finish to kill off a resilient Mainz side.
Schalke kept up their domestic comeback to beat bottom-placed Eintracht Braunschweig 3-1 for their third straight win to remain third, a point behind Dortmund.
VfB Stuttgart lifted themselves out of the relegation zone, beating 10-man Hamburg SV 1-0, who dropped to 16th place.
In the late game Borussia Moenchengladbach produced an explosive three-goal 12-minute spell in the first half to cruise past Hertha Berlin 3-0, Juan Arango scoring one and setting up another. Gladbach are fifth on 42 points, two behind Bayer Leverkusen who host Hoffenheim on Sunday.
In Mainz, the first opportunity of the game fell to Arjen Robben as early as four minutes when the home defence failed to clear their lines from a cross and the ball fell kindly to the Dutchman but as he pulled his foot back to drill the ball into the net, he caught his boot in the turf and subsequently failed to connect with the shot allowing Loris Karius to make the save.
Mainz were undoubtedly the better side in the opening 45 minutes and they had a couple of half chances to take a surprise lead. Some neat football from Mainz on seven minutes cut the Bayern defence open allowing Johanne Geis through on goal but instead of shooting he opted to pick out Nicolai Muller at the back post but failed to find the pass and the chance was ultimately wasted.
Shinji Okazaki went closest for the hosts on 37 minutes when he latched onto a wonderful through pass but hit the post before a late offside flag was raised.
The second-half began with a bang when Maxim Choupo-Moting saw his pile-driver smash agonisingly off the post with Manuel Neuer well beaten just a minute into the second period.
The further the match went on the more the league leaders grew into the game and they almost scored on 54 minutes when Mario Mandzukic rose highest to deliver a wonderful header at goal from David Alaba's cross but Karius - who had a terrific match - made a wonderful save.
Karius produced another fantastic save to deny Franck Ribery on 67 minutes when the young German goalkeeper was at full stretch to save the Frenchman's shot with his legs.
Gotze was introduced on 65 minutes and change the game for Pep Guardiola as the midfielder crossed for the unmarked Schweinsteiger whose header finally beat Karius.
The 21-year-old doubled Bayern's lead on the stroke of full-time with a simple tap-in after Ribery turned Karius.
The two goal defeat was rather harsh on a Mainz side who had plenty of chances to pull off a surprise result but ultimately just fell short. Thomas Tuchel's side had been the last side to prevent Bayern from scoring in a league contest back in April 2012 and at times it looked as though history would repeat itself but Gotze had other ideas.
Mainz remain three points behind the Champions League spots.
- Sports & Recreation
- Mario Gotze
- Bastian Schweinsteiger