Beltran pulled a shot down the left-field line for his 27th home run. John Jay, who singled ahead of Beltran's home run, doubled and scored a run in the sixth to beat Madison Bumgarner (12-7).
Wainwright (10-10) gave up one run and five hits over seven innings. He walked three but struck out seven in posting a win for third consecutive start.
Marco Scutaro's sacrifice fly with the bases loaded in the fifth spoiled Wainwright's shutout bid.
Jason Motte pitched the ninth, walking one and striking out two, for his 25th save.
Bumgarner gave up just three hits and a walk, while striking out seven, over six innings.
Jay led off the St. Louis first with a single and, after a force out, Beltran connected for his home run. Bumgarner didn't give up another hit until Jay opened the sixth with his double.