The Bavarians, who squandered a bagful of chances, hit the woodwork and conceded two goals in the second half, took the lead through Serge Gnabry in the 15th minute.
He set up Philippe Coutinho 10 minutes after the restart for their second but Kai Proeger's powerful volley cut the deficit in the 68th.
Robert Lewandowski chipped the keeper in the 80th to make it 3-1 but a sensational 30-metre missile from Jamilu Collins four minutes later renewed the hosts' hopes and set up a nervous finale.
Bayern are top on 14 points, one ahead of Leipzig who were joined on 13 by Schalke in third after a fourth straight win.
Borussia Dortmund, on 10 points, host Werder Bremen later on Saturday.