Adam Frazier's game-ending single capped a two-run rally in the ninth inning that lifted Pittsburgh to a 4-3 victory Sunday.
Francisco Cervelli reached on an infield single leading off the ninth against Brett Cecil (1-3), and Jordy Mercer's one-out double scored pinch-runner Josh Harrison with the tying run. Jose Osuna grounded out, David Freese was intentionally walked and Frazier lined a single to center.
Frazier's hit was the first walkoff hit of his career and it came just two days after Josh Bell got his first with a three-run homer in the ninth off Seung Hwan Oh.
Wade LeBlanc (4-2) pitched a hitless ninth. Pirates starter Trevor Williams gave up two runs and 10 hits in 5 2/3 innings.
Yadier Molina had put St. Louis ahead 3-2 with an eighth inning home run, the first allowed by Juan Nicasio this year.
Pirates starter Trevor Williams gave up two runs and 10 hits in 5 2/3 innings. He singled in the third for his first major league hit after an 0-for-21 start at the plate.
Cardinals starter Carlos Martinez (7-8) allowed two runs and five hits in seven innings, and had an RBI single in the sixth.
Andrew McCutchen's run-scoring single put Pittsburgh ahead in the fifth, and Matt Carpenter's RBI double tied the score in the fifth.
Max Moroff hit his first big league home run for the Pirates, a line drive off the right-field foul pole in the fifth. Moroff had 18 homer runs this season with Triple-A Indianapolis but was 4 for 48 in the majors.
Cardinals rookie Magneuris Sierra, brought back from Triple-A on Saturday, had four hits, stole a base and scored a run.
Adam Wainwright (10-5, 5.20 ERA) is to start Monday at the New York Mets. He is 8-2 in his last 11 starts, winning his last three.