Randy Johnson (8-5) gave up three runs on four hits and four walks in 5 1/3 innings to win for the fifth time in his last six decisions.
Bengie Molina had two hits and two RBI, and Pablo Sandoval had an RBI and two runs scored for San Francisco, which has won five of seven.
Chris Carpenter (5-3), previously 3-0 at home this year, allowed six runs on 11 hits in five innings for St. Louis, which has lost six of seven.
Albert Pujols powered the Cardinals with two home runs and three RBI, to finish the month with 14 home runs and 35 RBI.
Copyright 2009 by United Press International.