Bayern led 1-0 thanks to an early Serge Gnabry goal and looked in cruise control, but the visitors scored three second-half goals to turn the match, and the Bundesliga title race, on its head.
Dortmund can go two points clear with one matchday remaining with a win on Sunday against Augsburg.
The win, Leipzig's first in Munich and only their second victory over the German champions, secured the visitors Champions League football next season.
Bayern came into the match secure in the knowledge that two wins in their last two games would snare an 11th straight league title.
Gnabry settled Bayern's nerves after 25 minutes, blasting a rising shot in off the left post, his fifth in his past four games.
Bayern looked to take the speed out of the game and exert control, but Leipzig struck against the run of play on the counter after 65 minutes.
Konrad Laimer, widely tipped for a move to Bayern in the summer, took advantage of a superb team move to rocket the ball home.
A shellshocked Bayern sought to fight back but soon found themselves behind, after Benjamin Pavard brought down Christopher Nkunku in the box.
The France forward smashed the ball home from the spot, giving home 'keeper Yann Sommer no chance. Leipzig won another penalty with four minutes remaining after a handball, with Dominik Szoboszlai slamming home.
- Schlotterbeck relegates Hertha -
Earlier on Saturday, an injury time goal from Bochum's Keven Schlotterbeck sent Hertha Berlin back to the second division, with a 1-1 draw in the German capital.
Dead last coming into the weekend, Hertha appeared poised to delay relegation for at least another week when Lucas Tousart headed in a second-half goal at Berlin's Olympic stadium.
But Schlotterbeck's header in the fourth minute of injury time secured Bochum a draw and sent Hertha back to the second division after a decade in the Bundesliga.
"We don't have to be ashamed of our performance today, we didn't get relegated because of today," Hertha manager Pal Dardai said after the match.
Berlin-born midfielder Kevin-Prince Boateng, who started his career at Hertha, then moved to Tottenham, AC Milan and Barcelona before returning, said with tears in his eyes: "You can't blame the team, relegation wasn't about today.
"I just love the club. It's just bitter."
Bochum's point meant they climbed one place clear of the relegation zone with one week remaining.
Elsewhere, Schalke striker Sebastian Polter scored late at home against Eintracht Frankfurt to give his side a 2-2 draw, claiming a crucial point against the drop.
Schalke, promoted at the start of the season, took the lead in the first minute as captain Simon Terodde headed in a free kick.
Daichi Kamada equalised 20 minutes later for the visitors and Tuta gave Frankfurt the lead 15 minutes into the second half, before Polter scored just his second of the season with five minutes remaining.
Union Berlin wasted a chance to close in on a first-ever Champions League appearance, losing 4-2 at Hoffenheim.
Union fell behind 2-0 following errors from Portuguese centre-back Diogo Leite.
Leite headed a ball goalwards into the path of Hoffenheim's Ihlas Bebou, who scored the opener, and then gave away a penalty which was converted by Andrej Kramaric.
Dutch defender Danilho Doekhi pulled a goal back for the visitors in first-half injury time, heading in a cross from captain Christopher Trimmel.
With Union pushing for an equaliser, Kramaric scored with one minute remaining to secure a 3-1 lead.
Both sides scored a goal in injury time as Hoffenheim climbed four clear of the relegation spots.
Werder Bremen ensured another year in the top division with a 1-1 draw at home against Cologne.
A first-half goal by Steffen Tigges gave Cologne the lead but Romano Schmid scored late in the second half to snare a point for the home side.