Vedad Ibisevic put the Bavarians' unbeaten league run under threat but late goals from Claudio Pizarro and the Spanish midfielder sealed an impressive comeback.
The home side opened the scoring just before 30 minutes had been played thanks to Vedad Ibisevic, but the guests threw players forward in the second period and eventually snatched a levelling goal through Claudio Pizarro before the Spaniard's late winner.
Bayern's win extends its lead at the top of the table, and ensures its 43-game unbeaten run in the league continues.
The visitors named an unchanged side for the first time in Pep Guardiola's reign, with rumored Juventus target Mario Mandzukic among the substitutes.
Stuttgart brought Rani Khedira and Timo Werner into its starting lineup and the latter should have opened the scoring in the eighth minute.
After Mohammed Abdellaoue lost possession inside the penalty area, the loose ball fell for the 17-year-old but he blazed over the crossbar without testing Manuel Neuer.
Bayern survived a penalty shout against Rafinha four minutes later as Werner's header struck the right back's arm inside the area, with referee Manuel Grafe not convinced as he waved home appeals away.
Guardiola's side was far from its normal fluent self was were punished in the 29th minute as Ibisevic netted his 10th league goal of the season.
Werner's deflected shot from the edge of the area dropped to the Bosnian striker via the boot of Abdellaoue, who looked offside, and he calmly fired past Neuer from 10 yards to give the hosts a deserved lead.
Thiago and Xherdan Shaqiri both went close to leveling for Bayern in the closing minutes of the first half but were unable to beat Sven Ulreich.
Ibisevic had a chance to double his tally, and Stuttgart's lead, early in the second half but he fired wide of goal after a mistake from Rafinha.
With 54 minutes played, the hosts had another chance to score, and they would have made it 2-0 had it not been for a goal-line clearance from Jerome Boateng.
Former Barcelona man Thiago and Thomas Muller were denied by Ulreich but substitute Pizarro had no problems beating the goalkeeper with a well-placed header in the 76th minute.
Fellow substitute Mandzukic had a chance to win the game in the closing minutes but Thiago spared Bayern's blushes with an acrobatic volley in the last seconds of the match.