The holders eased to victory over Atletico Madrid in their opening game and then saw off Lokomotiv Moscow but looked as though they might come unstuck in Austria when Masaya Okugawa levelled matters at 2-2 in the 66th minute - just 42 seconds after he was introduced as a substitute.
Jerome Boateng, Leroy Sane, Lewandowski and Lucas Hernandez all scored inside the final 11 minutes to clinch the points, however, with Bayern earlier bouncing back from Mergim Berisha's opener to lead through a Lewandowski penalty and Rasmus Kristensen's own goal.
The late show leaves Bayern sitting pretty at the summit of Group A with nine points, five ahead of second-placed Atletico Madrid.