Dortmund, who had won their four previous games in all competitions, scored twice with Erling Haaland in the opening nine minutes and Poland striker Lewandowski responded with a brace of his own in an explosive first half.
But a goal from Leon Goretzka in the 88th minute put the hosts in front and Lewandowski scored his third in the 90th to kill off the game.
“It is currently the case that if an opponent gets a chance, we get punished,” said Bayern coach Hansi Flick. “But we shook ourselves after 2-0 and showed that we won’t have it taken away from us.
“We deserved the win in the end because we dominated the game for an hour. The team showed it was awake after going 2-0 down.”
Lewandowski, chasing Gerd Mueller’s legendary record of 40 league goals in one season dating back from the 1971-72 campaign, now has 31 goals with 10 league games remaining.
Bayern, hunting a record-extending ninth consecutive league title, are on 55 points, two ahead of RB Leipzig, winners 3-0 at Freiburg. Dortmund dropped to sixth on 39.
The league’s two best attacks lived up to their reputation in Der Klassiker with a stunning four-goal first half performance in an empty Allianz Arena.
In a flawless start, Dortmund, who had won the last four games in all competitions, were 2-0 up by the ninth minute with Haaland thundering in a shot and tapping in a cutback to take his league tally to 19 goals.
Bayern, however, quickly worked their way back, took control and struck twice with Lewandowski in the 26th minute and a 44th minute penalty for a foul on Kingsley Coman, to send the teams level at halftime.
“We started well but we should have kept it up,” said Dortmund’s Emre Can. “I am very disappointed. At some point we did not play football any more. It was not good enough today.”
Both took their foot off the gas after the break and Haaland had to be taken off injured on the hour with the visitors looking content with the draw, unwilling to risk too much in search of a winner.
Bayern pushed for a third goal and had their chances before Goretzka volleyed in a bad clearance to turn the game around and Lewandowski capped a superb performance, rifling in from the edge of the box.
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies