Richie Palacios drove in two runs and made a homer-robbing catch for the Cardinals, who finished with 15 hits and snapped their four-game losing streak.
Pete Alonso hit his 39th homer for the Mets, whose four-game winning streak came to an end.
Cardinals starting pitcher Dakota Hudson (5-0) allowed two runs on five hits in 5 1/3 innings. He struck out seven and walked two.
Mets starting pitcher Carlos Carrasco (3-7) allowed three runs on nine hits in fourth innings. He struck out three and walked nobody.
Palacios kept the Mets off the scoreboard in second inning with a leaping catch at the center field wall to rob DJ Stewart of a solo homer.
The Mets broke on top in the third inning. After Omar Narvaez drew a leadoff walk, then Rafael Ortega reached on a fielder's choice grounder and scored from first base on Jonathan Arauz's hit-and-run single.
The Cardinals tied the game 1-1 in the bottom of the inning on singles by Tommy Edman, Alec Burleson and Goldschmidt.
Alonso's 423-foot homer in the fourth inning put the Mets back on top 2-1.
The Cardinals moved ahead 3-2 in the fifth inning. Burleson hit a double and Goldschmidt knocked Carrasco out of the game with his 20th homer of the season.
St. Louis expanded its lead to 7-2 in the seventh inning. Goldschmidt hit a single and Nolan Arenado walked to set the stage. Willson Contreras hit an RBI single, Jordan Walker hit a run-scoring double and Palacios capped the rally with a two-run single.
The Mets cut their deficit to 7-3 in the eighth inning. Francisco Lindor hit a one-out single and Alonso reached base with two outs after striking out on a wild pitch.
Francisco Alvarez hit a single that Tyler O'Neill misplayed in left field. One run scored, but Alonso was thrown out at the plate to end the inning.
—Field Level Media