Niko Kovac's men needed to match Borussia Dortmund's result at home to Fortuna Dusseldorf, but Lucien Favre's side ran out a 3-2 winner, meaning the Bundesliga title will be decided on the final day of the season.
Bayern crafted the better opportunities in an even first half, but Peter Gulacsi rose to the challenge and twice kept Serge Gnabry at bay.
Goretzka's emphatic strike early in the second half was then contentiously wiped out because of an offside against Robert Lewandowski and Leipzig held on to ensure Dortmund — two points adrift of the top — remains in the hunt next week.
Leipzig made a promising start and troubled Bayern a couple of times in the first 16 minutes, as Yussuf Poulsen shot wide of the left-hand post before Timo Werner saw a seemingly goal-bound effort crucially blocked.
Bayern gradually improved and Gulacsi produced a vital save to deny Gnabry from close range after Lewandowski's solo run and cross in the 29th minute.
Gnabry went close again just before the break from a tight angle, but again Gulacsi was there to block the winger's volley.
Bayern upped the ante again after the interval, with Kingsley Coman's rasping 25-yard drive testing Gulacsi.
The goalkeeper was unable to prevent Goretzka smashing home in the 51st minute after Ibrahima Konate's poor headed clearance, but luckily for Leipzig a VAR review saw the goal disallowed for the most marginal of offside calls against Lewandowski in the build-up.
Despite Bayern's relentless pressure towards the end it was unable to make the breakthrough, as Gulacsi managed to save a clever Franck Ribery flick and Lewandowski's 89th-minute free-kick went agonisingly wide of the bottom-right corner.