Bundesliga top scorer Gomez took his league goal tally to 27 and Franck Ribery and Arjen Robben scored twice each as Bayern moved up to 62 points, three behind second-placed Bayer Leverkusen who drew 1-1 with Hamburg SV.
Bayern can still finish second to book an automatic group stage spot with a win next week if Leverkusen lose, due to a far better goal difference.
The top two Bundesliga teams gain automatic qualification for the Champions League group stage while the third team will play a qualifying round.
"We can enjoy our third place now," said interim coach Andries Jonker. "Maybe we will even get the chance to finish higher."
Fourth-placed Hanover 96 will have to settle for a Europa League spot after losing 2-1 at VfB Stuttgart to drop five points behind Bayern. Mainz 05 will also play in Europe, clinching fifth place with a fine 3-1 win at Schalke 04.
Champions Borussia Dortmund, who secured the title last week, sobered up with a 2-0 defeat to Werder Bremen, who made sure of their Bundesliga spot for next season after climbing to safety and 12th place on 41 points.
Borussia Moenchengladbach scored twice in the final minutes to beat Freiburg 2-0 for their third straight win and keep their hopes of staying up alive after moving into the relegation play-off spot.
Eintracht Frankfurt dropped to 17th place following their 2-0 defeat to visitors Cologne with some 150 angry Frankfurt supporters storming briefly onto the pitch at the end of the game and police using tear gas to contain them and keep them away from players and coaching staff.
Bayern knew they would find little resistance against injury-plagued St Pauli with their coach Holger Stanislawski making his last home appearance at the Millerntor stadium after 18 years as player, vice president and coach to join Hoffenheim.
The Bavarians, however, showed no mercy, taking full advantage of their opponents' defensive blunders to take a 2-0 lead into the break. Gomez grabbed his second, again from close range seven minutes after the restart, and Dutchman Robben added another two minutes later to put the game beyond the hosts, their relegation fate sealed after about an hour.
Bayern struck another three times in six minutes late in the second half with Robben's well-struck 12-metre header from a Ribery cross, Gomez and Ribery himself to ensure St Pauli's highest Bundesliga home defeat.
With their automatic Champions League qualification suddenly on the line and "Heynckes out" chants growing louder, Stefan Kiessling rescued a point when he failed to connect fully with a cross inside the box but still wrong-footed Hamburg goalkeeper Frank Rost.
"The early goal rattled us and we did not work well as a team," said Heynckes.. "Against Freiburg (next week) we will be a completely different team. We have been second for a long time this season and we will still be there after the last game."