Teenage striker Joshua Zirkzee put Bayern ahead before Benjamin Pavard’s own goal levelled for Gladbach, but Goretzka netted his third goal in five league games with four minutes remaining.
Even without the suspended Robert Lewandowski and Thomas Mueller, Bayern earned their 13th straight win in all competitions to re-establish their seven-point lead over Borussia Dortmund at the top of the table with three matches left.
Victory at relegation-threatened Werder Bremen on Tuesday will confirm Bayern as German champions for the 30th time in Hansi Flick’s first season in charge.
“I’m happy that the team got the job done with some hard work – those were three important, ‘big’ points,” said Flick.
Second-placed Dortmund had earlier trimmed Bayern’s lead to four points when Erling Braut Haaland’s last-gasp header grabbed a dramatic 1-0 win at Fortuna Duesseldorf.
Bayern had to dig deep again, having also laboured to victory by the same margin in Wednesday’s German Cup semi-final win over Eintracht Frankfurt.
Gladbach made a fast start but were denied an early lead as Jonas Hofmann’s strike was ruled out for offside.
But visiting goalkeeper Yann Sommer gifted Bayern a 26th-minute advantage when his dreadful pass across the edge of his area was met by the 19-year-old Zirkzee, who coolly found the net to score his fourth Bundesliga goal from just eight appearances.
Gladbach deservedly drew level though when Pavard turned Patrick Herrmann’s cross into his own net eight minutes before the break.
Both sides had second-half chances, but Goretzka settled matters when he turned home Pavard’s low cross.
Haaland strikes on return
Earlier, Dortmund were heading towards a frustrating draw at relegation-threatened Fortuna when Haaland headed home centre-back Manuel Akanji’s cross in the 95th minute.
“It’s a bit of a lucky thing that we were able to walk away with the win today,” admitted Dortmund goalkeeper Roman Buerki.
With time almost up, Haaland, who returned from injury as a second-half substitute, flicked a header into the bottom corner for his 14th goal in 15 games since joining Dortmund from Salzburg in January.
Dortmund had endured a nervous final 10 minutes as Duesseldorf substitute Steven Skrzybski twice hit the post and fired wide before Haaland struck.
Haaland’s goal, coupled with Bayern’s win, ensured Dortmund qualified for next season’s Champions League group stage.
Duesseldorf, who occupy the relegation play-off spot, are now only ahead of second-bottom Werder Bremen on goal difference following their 5-1 thumping of Paderborn.
Lifeline for Bremen
Bremen, who have spent more seasons in the Bundesliga than any other club, responded to back-to-back home defeats with an emphatic away victory in pouring rain as Davy Klaassen netted either side of a goal by Japanese forward Yuya Osako in the first half.
Maximilian Eggestein made it four with only an hour gone, after Bremen forward Milot Rashica also had a penalty saved, before Abdelhamid Sabiri scored a consolation for rock-bottom Paderborn.
Bremen substitute Niclas Fuellkrug capped a fairytale return from a serious knee injury when he slotted home the fifth goal late on.
Paderborn are now mathematically certain to finish in the bottom three.
Ten-man Hertha Berlin suffered a 4-1 thrashing at home by Eintracht Frankfurt after defender Dedryck Boyata was sent off on the stroke of half-time for bringing down Bas Dost.
Krzysztof Piatek gave Hertha an early lead, but Frankfurt roared back with a goal from Dost, two from Portuguese forward Andre Silva and one for French defender Evan N’Dicka.
Freiburg came from two goals down to earn a 2-2 draw at Wolfsburg in a game which saw the hosts’ striker Wout Weghorst have two goals disallowed by VAR.
Union Berlin pulled away from the relegation places with their first victory since February, winning 2-1 at Cologne.