With the game level at 1-1 in the sixth inning, Gomes - who was a late addition to the line-up when Shane Victorino was scratched with back tightness - launched a 2-2 pitch from Seth Maness over the wall in left to put the Sox on top.
Gomes had also contributed to Boston's first run in the fifth, getting a walk to help advance David Ortiz, who went on to score on a sacrifice fly from the slumping Stephen Drew.
It was a big win for the Red Sox as they rebounded from a tough loss in game three, which came on an obstruction call in the ninth.
Game four ended in unconventional fashion too as Boston closer Koji Uehara picked off pinch runner Kolten Wong at first for the final out.
The Cardinals got RBI hits from Carlos Beltran and Shane Robinson, while Felix Doubront got the win for Boston with 2 2/3 innings in relief of Clay Buchholz.
The two teams will go again in game five in St Louis on Monday night before the best-of-seven series heads back to Boston for game six on Wednesday.