The winger scored twice in the latter 45 minutes, alongside goals from Arjen Robben and Mario Mandzukic, to cancel out the visitor's first-half opener.
The European champion's 33-game unbeaten run in the Bundesliga looked to be under threat when Shawn Parker gave Mainz a shock halftime lead.
But coach Pep Guardiola brought on midfielder Mario Gotze at halftime and the Germany international and Thomas Muller inspired the side to a second-half comeback.
Gotze laid on goals for Arjen Robben and Mario Mandzukic, and Muller scored twice to ensure Bayern is now just two games away from leveling the Bundesliga's longest unbeaten run, held by Hamburg.
Bayern wingers Franck Ribery and Xherdan Shaqiri missed the match through ankle and hamstring injuries, while defender David Alaba dropped to the bench.
Robben, Mandzukic and Diego Contento came into Bayern's side, while Mainz made six changes to the team that drew with Hoffenheim before the international break, with goalkeeper Christian Wetklo the headline inclusion.
Mainz came into the match without a win in its last five, but set about frustrating Bayern and showed some attacking threat, with Johannes Geis firing over the bar with his left foot in the 12th minute.
Bayern lost Brazil defender Dante to injury with halftime looming and the club was stunned moments later, falling behind after Parker capitalized on a Jerome Boateng error.
The defender missed Julian Baumgartlinger's routine ball through the middle and Parker raced clear, rounding Bayern goalkeeper Manuel Neuer before slotting into an empty net.
Gotze entered the fray at the break in place of Rafinha and that proved to be an inspired move as the midfielder made an instant impact.
The former Borussia Dortmund man cut open the Mainz defense with a through ball to Robben just four minutes after the break and the Holland winger equalized with a measured left-foot finish inside the near post.
Bayern was in front just two minutes later, with Robben turning provider on this occasion.
Robben laid the ball off to Muller and the Germany forward kept his composure, slotting past Wetklo from the center of the penalty area.
Mainz was struggling to live with Guardiola's men and the home side gave itself breathing space in the 69th minute, with Gotze the architect once again.
Gotze got to the line and cut back for Mandzukic, with the Croatia striker shooting into the far corner, before Muller put the icing on the cake with eight minutes to play.
This time it was from the penalty spot, after Junior Diaz fouled Bastian Schweinsteiger, and Muller converted to cap off Bayern's excellent second half.