SAN FRANCISCO -- Johnny Cueto pitched a five-hitter and helped his own cause with a go-ahead sacrifice fly in the fourth inning Thursday night, leading the San Francisco Giants to a 6-2 victory over the St. Louis Cardinals in the opener of a four-game series.
Hunter Pence hit a two-run homer, Buster Posey had four hits and Denard Span, demoted to eighth in the batting order, laced a key two-run single, helping the Giants (78-68) move two games ahead of the Cardinals (76-70) in the National League wild-card race.
The Giants also gained a game on the Los Angeles Dodgers (82-64) atop the NL West, but still trail by four with 16 to play.
The New York Mets (77-69), who were idle Thursday, reside between the Giants and Cardinals in the second wild-card spot, one game ahead of St. Louis.
Cueto (16-5) became the NL's fourth 16-game winner with his league-leading fifth complete game.
He gave up two runs on five hits in the third and fourth innings, but surrendered neither a hit nor a run in his other seven innings en route to his second consecutive win.
He finished with one walk and seven strikeouts.
Cueto outpitched Cardinals right-hander Adam Wainwright, who had held a 2-1 advantage in their three previous career head-to-heads.
Wainwright (11-9) was roughed up for four runs and nine hits in 5 2/3 innings. He walked three and struck out two.
After Cueto's sacrifice fly contributed to a two-run fourth that gave the Giants the lead for good, San Francisco gave him some breathing room with a two-run seventh against the St. Louis bullpen.
Posey's fourth hit opened the inning against the second Cardinals pitcher, Zach Duke.
Duke left the game with two on and two out, before right-hander Matt Bowman gave up an infield single to Nunez and Span's game-breaking, two-run single that opened a 6-2 lead.
Span was moved from first to eighth in the Giants' lineup in manager Bruce Bochy's response to getting swept by the San Diego Padres earlier in the week. The Giants entered the series with the NL's worst record in the second half.
Span finished the game with two of the Giants' 12 hits. Angel Pagan, the new leadoff man, also had two hits.
Randal Grichuk had a single and a double for the Cardinals, who began a 10-game trip with the best road record in the NL (43-28).
Wainwright aided in the Giants' two-run fourth inning by issuing a leadoff walk to Brandon Belt.
After Eduardo Nunez doubled Belt to third, the Cardinals elected to walk Span intentionally, loading the bases for Cueto.
His sacrifice fly gave the Giants a 3-2 lead, and Pagan followed with an RBI single, making it a two-run game.
The Cardinals erased the earlier 2-0 deficit created by Pence's homer with single tallies in the third and fourth.
Jedd Gyorko and Grichuk drove in the runs with singles, after which the Cardinals stranded a pair of baserunners in both innings.
NOTES: Cardinals manager Mike Matheny announced before the game that LHP Jaime Garcia has been demoted to the bullpen and will be replaced by RHP Alex Reyes as the starter in Sunday's series finale. ... The Cardinals activated RHP Trevor Rosenthal (shoulder inflammation) from the disabled list. ... Before announcing his lineup changes, Giants manager Bruce Bochy cancelled batting practice and pushed back the players' arrival time to 5 p.m. ... Also at stake in this series: The home-field advantage in a potential wild-card tiebreaker game, which would go to the team that won the season series. The Cardinals beat the Giants two of three in St. Louis earlier this season.