Japan international Shinji Kagawa snatched the winner in the 77th minute as Dortmund set a club record of eighth straight league wins and extended their unbeaten run to 18 games.
Jakub Blaszczykowski had put the champions in front in the 26th minute before their former player Mohamed Zidan levelled for Mainz in the 74th.
"To react to the equaliser in such a way was really good," said Dortmund coach Jurgen Klopp.
Klopp's team were on top throughout but missed half a dozen clear opportunities. Kagawa's goal was his eighth of the season in the league.
Bayern's title hopes were dealt a blow as their sixth defeat of the season meant they stayed on 48 points.
Germany international Stefan Kiessling tapped in the first Leverkusen goal 11 minutes from time after taking advantage of confusion in the opposition box.
Karim Bellarabi made it 2-0 in the 90th minute after Bayern had squandered a host of chances mainly through Arjen Robben.
"There is no need to talk about the Bundesliga title today," said Bayern sports director Christian Nerlinger.
"It is not that we have written the title off yet but... we are bitterly disappointed."
Despite starting with France playmaker Franck Ribery on the bench due to a minor thigh injury, the Bavarians created several chances.
Dutch winger Robben, who scored twice in the 3-2 midweek win by Netherlands over England at Wembley, was repeatedly denied by goalkeeper Bernd Leno.
SAVE OF THE GAME
Bayern keeper Manuel Neuer produced the save of the game when he stopped a volley by Kiessling from point-blank range.
Neuer was powerless though to stop Kiessling when the striker was left unmarked in front of goal as he converted an overhead-kick from Gonzalo Castro.
Bayern then poured forward for the equaliser and were caught out when the 20-year-old Bellarabi grabbed his first Bundesliga goal.
VfB Stuttgart went goal crazy at Hamburg SV, winning 4-0. Two penalties by Zdravko Kuzmanovic and a goal apiece for Vedad Ibisevic and Martin Harnik took the visitors up to eighth position on 32 points.
Hamburg had striker Paolo Guerrero sent off for a flying challenge from behind on goalkeeper Sven Ulreich near the corner flag after 54 minutes, an offence that is almost certain to mean a lengthy ban for the Peruvian.
Hertha Berlin ended a six-game losing streak in the league with a 1-0 victory over Werder Bremen courtesy of Nikita Rukavytsya's 63rd-minute effort, their first win under former Bremen coach Otto Rehhagel.
Relegation-threatened Freiburg climbed off the bottom with a 2-1 triumph over Schalke 04 who lost ground in the title race and are fourth on 44 points.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.