"For such a brilliant game it's worth being a coach," said Stuttgart coach Bruno Labbadia.
Ivan Perisic had scored what looked like Dortmund's winning goal in the 87th minute, five minutes after Mats Hummels had equalized for the league leaders.
"That was a crazy game. I never experienced such a game with the lead changing hands like that," said an exhausted Dortmund coach Juergen Klopp. "Stuttgart played a killer game."
Julian Schieber scored a quickfire double to put Stuttgart 3-2 up after 79 minutes.
Dortmund was 2-0 up through a first-half goal by Shinji Kagawa and a 49th-minute effort by Jakub Blaszczykowski before Vedad Ibisevic got Stuttgart's first in the 71st.
Dortmund stretched its club record unbeaten run to 22 games and is six points ahead of Bayern, which can cut the gap to three with a win at Nuremberg on Saturday. The sides meet in a mouthwatering tie on April 11.
Stuttgart is unbeaten in six games and fifth ahead of the weekend's games.
Robert Lewandowski had an effort cleared off the line and Kevin Grosskreutz hit the crossbar before Kagawa finally found the breakthrough in the 33rd.
Dortmund captain Sebastian Kehl headed the ball down to give the Japan star a simple finish for his 12th goal of the season.
The home side had 16 attempts on goal in the first half, compared to two for the visitors.
Hummels crossed for Blaszczykowski to deservedly made it 2-0 after the break, but Labbadia was pleased to see "the team didn't give up."
William Kvist struck the post after a fine run from deep in the 63rd, before Ibisevic scored thanks to a classy backheel from Georg Niedermeier.
Schieber, who missed a great chance in the first half, equalized six minutes later when he eluded Hummels and rounded Roman Weidenfeller before slotting inside the post.
The 23-year-old added another two minutes later with a fierce shot through Weidenfeller's legs.
Hummels atoned for his earlier error with a low strike inside the right post, before Perisic thought he'd won the game.
But second half substitute Gentner took advantage of some panicky defending before rifling a powerful shot under the crossbar.