Seth Maness relieved, and Gomes greeted him by crushing a pitch over the left field fence and into the Red Sox bullpen.
Ortiz went 3-for-3 with two runs scored for Boston, which rebounded to even the series at 2-2 following two consecutive losses.
Felix Doubront allowed one run over 2 2/3 innings in relief of starter Clay Buchholz to earn the victory and Koji Uehara secured it with a scoreless, ending the game by picking off pinch-runner Kolten Wong at first base.
Matt Carpenter and Carlos Beltran each drove in a run for the Cardinals, who will host Monday's Game 5.
Man spent 15 hours in jail for plugging electric car into an outlet at a school
Texas principal bans speaking Spanish, stirs controversy