Bayern, who could seal the title on Tuesday at Werder Bremen, are on 73 points, with Dortmund on 66. Gladbach remain fourth on 56.
The visitors thought they went ahead after 16 minutes through Jonas Hofmann but the goal was ruled out for offside.
Bayern took the lead after 26 minutes when Sommer passed the ball into Zirkzee's path to score in an empty net.
Gladbach equalised 10 minutes later Pavard scored an own goal from Patrick Herrmann's cross.
With four minutes remaining, Goretzka tapped home from close range to secure the three points for Bayern.
"We can also win these tough matches," said Neuer. "Our plan was a bit different. We did not have that much possession and pressed more in midfield."
"We let them come to us. That was the plan."