The Cardinals won their fifth in a row and brought the Astros to within one of becoming the first team in the majors with 60 losses this season.
Brett Wallace put Houston in front 4-3 in the top of the seventh with an RBI single, but St. Louis rallied in the bottom half of the inning to take its first lead of the contest.
Tony Cruz was hit by a pitch leading off the inning and one out later Wesley Wright came on to relieve Jordan Lyles. Carpenter promptly hit a 2-1 pitch from Wright (0-3) over the wall in right to give the Cardinals the lead.
That gave the win to Seth Marness (5-1), who allowed a run on two hits while working the sixth and seven innings. Edward Mujica put runners on first and second with one out in the ninth, but then got Carlos Pena to ground into a game ending double play to record his 25th save.