Marco Reus gave Dortmund the lead after three minutes and Jakub Blaszczykowski doubled the advantage in the ninth minute from the spot. Stefan Reinartz scored a brace in the 58th and 62nd minutes to equalise only to see Robert Lewandowski make it 3-2 seconds later.
Blaszczykowski saw his second penalty attempt stopped in the 70th minute but Dortmund held on for the victory, their fourth in a row as they continue to trail Bayern by 12 points.
Leverkusen suffered their first Bundesliga loss at home this season as they dropped down to third.
Dortmund were without first-choice goalkeeper Roman Weidenfeller, who missed the match with the flu and was replaced by Mitchell Langerak.
But the visitors grabbed the lead after just three minutes with Lewandowski sending a superb through ball for Reus, who hit a looping shot over Leverkusen goalkeeper Bernd Leno.
Leno then dragged down Lewandowski in the eighth minute for a Dortmund penalty which Blaszczykowski converted into the lower left corner to make it 2-0.
Leverkusen missed two chances to pull a goal back in the first half with Stefan Kiessling's header going over the bar in the 14th minute and Andre Schurrle striking just high a minute before the break.
The hosts continued their push forward but were unable to use a double chance in the 50th minute with Langerak stopping Kiessling's close-range shot and Dortmund defender Mats Hummels blocking Schurrle's rebound attempt at the line.
Leverkusen finally made it 2-1 after 58 minutes as Kiessling looped the ball over the defence before Reinartz poked home from six yards.
Leverkusen equalised four minutes later from a set piece with Gonzalo Castro's free-kick going to Sebastian Boenisch, who headed it back across goal for Reinartz to nod home.
Dortmund answered right back in the 63rd minute with Philipp Wollscheid playing a poor back pass to Leno, who fended the ball away but right into the path of Lewandowski to give him an easy finish.
Dortmund missed a chance to re-establish the two-goal lead in the 70th minute as Leno held Blaszczykowski's spot kick to the lower right corner after Boenisch took down Lewandowski.