Bayern made two changes from the narrow win over Bayer Leverkusen in their last match of 2020, as Joshua Kimmich and Leroy Sane were both recalled.
Sane almost marked his return to the line-up with an early goal for the hosts in the ninth minute with a strike inside the box that took a deflection and almost crossed the line but goalkeeper Finn Dahmen made a great reflex save.
Mainz were growing in the game midway into the first stanza, putting Bayern under pressure and Jonathan Burkardt gave the visitors a shock lead in the 32nd minute with a thumping effort past goalkeeper Manuel Neuer after a through ball over the defence.
Lewandowski came very close to getting the equaliser for the Bavarians four minutes later with powerful strike towards the top corner that was acrobatically parried away by Dahmen.
Jan Siewert's charges were threatening to capitalise on Bayern's high line and Alexander Hack doubled their lead on the brink of half-time with a header at the back post after an inviting free-kick by Daniel Brosinski.
Mainz had a big chance to make it 3-0 three minutes from the break after Danny Latza beat the offside trap to go clear on goal inside the box but he fired his strike straight at Neuer, in a one-on-one situation.
Bayern pulled a goal back two minutes later after Joshua Kimmich headed home a flicked assist by Lewandowski at the far post from a cross by Serge Gnabry, 1-2.
Hans-Dieter Flick's troops had their tails up and Sane levelled matters ten minutes inside the second stanza with a moment of individual brilliance after he cut inside the box from the corner of the box and smashed a left-footed shot into the bottom corner, 2-2.
Robin Quaison was unlucky not to make it 3-2 for Mainz on the hour-mark after unleashing a volley from outside the box that beat Neuer but crashed against the crossbar.
The Bavarians thought they went ahead in the 65th minute after Leandro Barreiro Martins turned Alphonso Davies' cross into his own net but the goal was disallowed for offside in the build-up by the Video Assistant Referee (VAR).
Second-half substitute Niklas Sule finally completed the comeback for the hosts in the last 20 minutes with a volley from a corner situation inside the box that took a slight deflection on its way to the back of the net.
Bayern had a wonderful chance to kill off the game with a penalty in the last quarter of an hour after Gnabry was brought down inside the box and Lewandowski made it 4-2 with a composed finish from the spot-kick, sending Dahmen the wrong way.
The Bavarians were running riot, as Lewandowski made it 5-2 and grabbed his brace seven minutes before time with a volley inside the box from Thomas Muller's cross and Flick's troops cruised to the top of the table by two points while Mainz remained second-from-bottom, five points from safety.