Jedd Gyorko and Matt Holliday also homered for St. Louis. Carpenter, Holliday, and Aledmys Diaz each had three hits as the Cardinals finished with 17 — including 13 for extra bases.
Gyorko and Pham led off the seventh with back-to-back home runs against reliever Nick Vincent (1-7) to break a 6-6 tie. Holliday extended St. Louis' lead to 9-6 with a solo shot in the eighth against Edwin Diaz. Pham and Carpenter each hit their second home runs, both solo shots, in the ninth.
Kevin Siegrist (5-2) allowed one run on two hits in 1 1/3 inning to get the win.
Franklin Gutierrez tied the game at 6-6 with a three run homer against Siegrist in the bottom of the sixth.