It started so well for Borussia Dortmund, who led 2-0 after just nine minutes with Erling Haaland scoring twice. However, the hosts came back and were level by half-time with Polish star Lewandowski bagging a brace.
It stayed 2-2 for much of the second half before Leon Goretzka and then Lewandowski sealed victory for Munich with goals in the last two minutes.
Both teams had been level on points in first and second place respectively ahead of the reverse fixture. But prior to their latest meeting there were four places and 13 points separating league leaders Bayern Munich and fifth-placed Borussia Dortmund. This was a clash of the two best attacks, with Bayern and Borussia having scored 115 (67/48) goals between them.
Edin Terzic, meanwhile, made four changes from the team that beat Monchengladbach in the DFB Pokal in midweek - two of them forced. Raphael Guerreiro and Jadon Sancho were both sidelined through injury, whilst Jude Bellingham and Mateu Morey made way with Nico Schulz, Thorgan Hazard, Thomas Meunier and Dan-Axel Zagadou all coming in.
BVB off to a flyer
Dortmund got off to a blistering start, not letting their hosts settle into the game and took the lead inside 78 seconds.
Munich dominated possession but Dortmund were clinical, and Bayern were caught cold for a second time when Schulz broke down the left and found Hazard, whose cross was tucked in at the near post by an alert Haaland inside nine minutes.
Leroy Sane's header onto the roof of the net from a narrow angle after a quarter of an hour was the first sight of goal for Bayern, who were now forcing the Black & Yellows into errors with their high pressing and soon had their first dangerous shots through Lewandowski and Muller.
Bayern fight back
Hansi Flick's troops pulled one back when Sane's low cross invited Lewandowski to tap in. Borussia dropped deeper and deeper now, with the Pole seeing an effort blocked before firing over the bar soon after.
However, Dahoud soon upended Coman in the box to gift Munich the chance to equalise - Lewandowski converting the penalty to level the scores before half-time.
BVB restarted the game with renewed courage having conceded their lead. They hit the side-netting through Hazard in the 47th minute and were then left bemoaning a decision by the officials and VAR, who let play continue after Kimmich brought down Marco Reus in the box.
Boateng also went unpunished after stepping on Haaland's Achilles tendon in the 53rd minute. The Norwegian, who was bleeding, had to come off and was replaced by Steffan Tigges.
And Haaland's absence seemed to spur on Bayern. Keeper Marwin Hitz parried a Kimmich shot and only just beat the onrushing Coman to the rebound. Niklas Süle headed over the bar and Lewandowski miscued from 20 yards before Hitz saved a deflected Serge Gnabry shot.
Bayern upped the pressure in search of the late winner, Kimmich seeing an effort blocked, but Goretzka rewarded their pressure two minutes from time. Muller's cross was blocked by Meunier but only as far as Goretzka, who volleyed past Hitz and into the bottom corner from just inside the penalty area.
And with Bayern in their stride and Dortmund searching for an equaliser, they wrapped up the points. Alphonso Davies broke into the Dortmund half and played the ball inside and Sane dummied it to Lewandowski, who fired a low strike from 20 yards into the bottom corner to complete a fine hat-trick against his former club.