The German and European champions fell behind to Niklas Sule's 34th-minute goal, but Mario Mandzukic and Thomas Muller struck either side of half time to ensure that Guardiola's side stayed top of the Bundesliga.
"We had a bit of luck," the Spaniard said in a press conference after the game.
"It certainly was not our best performance but we won. Not everything went perfectly, so we will need to correct the way we play."
Bayern's next league game sees them host Augsburg next Saturday.