The Bavarians took a commanding lead into half time after a dominant opening 45 minutes at the WWK Arena.
Serge Gnabry opened the scoring in the 28th minute before Luis Diaz doubled their advantage seconds before the referee brought the first half to a close.
Bayern looked to have the result completely wrapped up when Michael Olise made it 3-0 three minutes after the restart but the hosts had other ideas.
Kristijan Jakic pulled one back in the 53rd minute before Mert Komur ensured there would be a grandstand finish when he made it 3-2 in the 76th minute.
Ultimately, Bayern were able to cling on for the win but it was a close-run encounter and they will be relieved to have claimed the three points in the end.
Elsewhere in the Bundesliga on Saturday, Stuttgart claimed a 1-0 win over Borussia Monchengladbach courtesy of Chema Andries 79th 79th-minute strike and RB Leipzig beat Heidenheim with Christoph Baumgartner (48') and Romulo (78') getting on the scoresheet.
Frankfurt claimed an impressive 3-1 win away from home against Hoffenheim. The match wasn't even as close as the scoreline might suggest after a Ritsu Doan brace gave the visitors a commanding lead before Can Uzun made it 3-0 in the 51st minute. A late Gischa Promel consolation goal gave the scoreline a bit of respectability for the home side.
Werder Bremen and Bayer Leverkusen played out to a thrilling 3-3 draw at the Weserstadion. The visitors held the advantage at half time after goals from Patrick Schick (5') and Malike Tillman (35') gave them a 2-1 lead after Romano Schmid pulled one back from the penalty spot in the 44th minute.
The fireworks really began in the second half with Schick adding his second of the game to put Leverkusen in a commanding position with a 3-1 lead.
However, the home side fought back bravely with Isaac Schmidt making it 2-3 in the 76th minute before Karim Coulibaly rescued a point with a strike four minutes into stoppage time.
St. Pauli beat HSV 2-0 at the Volksparkstadion thanks to goals from Adam Dzwigala (19') and Andreas Hountondji (60').