Adam Wainwright earned his 16th win and matched his career best withrs.
Eighth-place hitter Peter Bourjos singled twice with an RBI, and seventh-place hitter Daniel Descalso walked twice and scored twice.
Wainwright (16-9) prevailed despite allowing three home runs to match his career worst.
He left after Starling Marte’s two-run shot shaved the lead to 5-4 with none out in the seventh. It was the first time he had allowed more than one homer all season.
Russell Martin and Jordy Mercer homered with the bases empty for the Pirates, who have lost three in a row.
Despite the damage, Wainwright didn’t face any batters with runners in scoring position. He lost his previous two outings, the last at Pittsburgh when he allowed three runs in six innings.
The first four Cardinals reached base in a three-run fourth that snapped a 2-all tie. Wainwright’s two-run single chased Jeff Locke (6-4), who walked five and was charged with five runs — four earned.
Wainwright also had a run-scoring groundout in the second and matched a three-RBI game against the Brewers July 4, 2010, in which he also threw a complete game in a 7-1 win.
Locke allowed a run in 71/3 innings with two walks against the Cardinals his last time out. He worked around a season-worst six walks to win at Milwaukee on Aug. 22.
Jhonny Peralta doubled to start the seventh and scored on a wild pitch by John Axford that put St. Louis up 6-4. Trevor Rosenthal got a day off, and Pat Neshek finished for his fifth save in eight chances.
Pirates: Pedro Alvarez missed his sixth straight game with left foot discomfort. Charlie Morton (hip) threw 76 pitches in a four-inning simulated game earlier Tuesday and could join the bullpen soon.
Cardinals: Kolten Wong didn’t start for the second straight game after banging his head making a catch. He pinch-hit in both games, and his homer tied it on Monday.
Pirates: Edinson Volquez (11-7, 3.45) has won seven of his last eight decisions. He is 4-6 with a 5.06 ERA in 14 career starts against the Cardinals.
Cardinals: Shelby Miller (8-9, 4.19) is 2-6 with a 4.98 ERA against Pittsburgh, including 2-2 this year.