Tim Locastro also hit a home run for the Mets, who earned their fourth victory in their last five games.
Mets starting pitcher Jose Quintana (1-4) allowed two runs on three hits and four walks in six innings. Trevor Gott earned his first save since 2020.
Cardinals starting pitcher Adam Wainwright (3-8) allowed three runs on four hits and three walks in six-plus innings. He struck out five.
Tyler O'Neill hit a homer for the Cardinals, who suffered just their third loss in eight games.
In his previous two starts Wainwright retired just 12 batters while allowing 15 runs on 18 hits. This time he allowed just one hit in his first three innings before the Mets surged ahead 2-0 in the fourth inning.
Jeff McNeil hit a one-out double that was nearly a homer. Right fielder Jordan Walker leaped at the fence to pull the ball back, but he couldn't complete the catch.
Alonso followed with his 37th homer of the season, a no-doubter well over the center field wall.
Quintana retired the first 10 batters he faced, with the help of Brandon Nimmo's diving catch in left field in the third inning that robbed Jose Fermin of a double.
Paul Goldschmidt hit a one-out single for the Cardinals in the fourth inning and Willson Contreras and O'Neill drew a two-out walks to load the bases. But Walker hit into an inning-ending fielder's choice.
The Mets pushed their lead to 3-0 in the fifth inning when Rafael Ortega and Nimmo drew walks and Francisco Lindor hit an RBI double.
The Cardinals cut their deficit to 3-2 in the seventh inning. O'Neill led off with a homer, the first Quintana allowed this season.
Walker walked and Andrew Knizner hit a single to chase Quintana. Pinch-hitter Alec Burleson greeted reliever Drew Smith with a sacrifice fly, then Fermin walked and Tommy Edman advanced the runners with a groundout.
But Goldschmidt grounded out to leave two runners in scoring position
Locastro hit his homer in the ninth inning to expand the Mets' lead to 4-2.
The Cardinals put runners on first and second base with two outs in the ninth, but reliever Trevor Gott struck out Goldschmidt to end the game to notch his first save this season.
—Field Level Media