
Robert Lewandowski put Pep Guardiola's side ahead following some desperate defending before Austrian international David Alaba doubled their advantage from long range late in the first half.
Franck Ribery marked his first start of the season after injury by finding the net with a deflected shot early in the second period, and the Frenchman was then struck in the face with the scarf of a spectator who invaded the pitch, before Pierre-Michel Lasogga got a late consolation for the hosts.
Elsewhere, Freiburg, Hoffenheim and Wolfsburg all beat lower-league opposition, while Borussia Moenchengladbach, who are second in the Bundesliga, won 2-1 at Eintracht Frankfurt.
Bayer Leverkusen needed penalties to win at regional league side Magdeburg, but it could have been worse for Roger Schmidt's side. AFP