Buster Posey and Joaquin Arias each hit a home run as the San Francisco Giants ended the Los Angeles Dodgers' postseason hopes with a 4-3 victory on Wednesday.
The Dodgers needed a win to remain a game behind St. Louis for the NL's final wild card spot with one left to play after the Cardinals fell to the Cincinnati Reds earlier in the day.
But with the loss, St. Louis will have a chance to defend its World Series championship.
"Everyone is disappointed. We thought we'd win this game," Dodgers manager Don Mattingly said.
Barry Zito (15-8) allowed two runs on six hits and a walk while striking out six over six-plus innings for the NL West-champion Giants. Sergio Romo stranded the game-tying run on second base in the ninth to record his 14th save of the season.
"We played this like a playoff game. It was very good for us. I'll play the starters again tomorrow to keep them sharp, but I don't know how long I'll play them," Giants manager Bruce Bochy said.
Chris Capuano (12-12) surrendered two runs on five hits in a three-plus innings for Los Angeles, which had its season-high tying six-game win streak snapped.
A.J. Ellis hit a two-run homer in defeat.
San Francisco struck first with Posey's leadoff homer into the left-center field seats in the second inning.
The Dodgers quickly answered in the bottom of the frame when Hanley Ramirez hit a one-out triple and came home on Luis Cruz's grounder to third, but Arias opened the third with a shot over the center-field wall to put the Giants back on top.
After Los Angeles left the tying run on second in the fourth inning, the Giants pulled further away in the fifth on Marco Scutaro's two-run double down the first-base line.
Arias reached base on a fielder's choice and Angel Pagan was intentionally walked before both came around to score on Scutaro's two-out hit, which made it a 4-1 game.
Zito was replaced by Guillermo Mota in the seventh inning after hitting Andre Ethier with a pitch, and Ellis greeted the reliever with a blast over the right-center field wall to bring the Dodgers within a run.
Los Angeles then ran itself out of the game-tying run, as Mark Ellis was thrown out at third while trying the stretch a double into a triple before Shane Victorino tripled to right field.
Victorino was stranded at third when new pitcher George Kontos fanned Matt Kemp.
"He got excited. I don't fault him for hustling," Mattingly said about Ellis' baserunning gaffe.
Ethier opened the bottom of the ninth inning with a single up the middle and pinch-runner Dee Gordon later stole second to place the tying run in scoring position with two outs, but Mark Ellis sent a liner to center field that was caught by Pagan.
Zito has won seven straight starts and the Giants have won each of his last 11 starts ... Capuano fell to 1-7 in 13 career meetings (nine starts) against San Francisco ... Scutaro extended his career-high hit streak to 19 games ... Dodgers first baseman Adrian Gonzalez went 1-for-4 to extend his hit streak to 14 games ... The Giants have won six of the last eight meetings between the teams and lead the season series, 10-7.