Updated

Elian Herrera kept the Dodgers' playoff hopes alive with an RBI single in the bottom of the ninth inning, lifting Los Angeles over the San Francisco Giants, 3-2, in the first of a three-game series at Dodger Stadium.

The win kept the Dodgers within two games of the St. Louis Cardinals for the NL's final wild card spot with two games left in the regular season.

Andre Ethier added a two-run homer for the Dodgers, who have won a season-high tying six straight games.

Brandon League (2-6) tossed a scoreless top of the ninth to earn the win.

Santiago Casilla (7-6) surrendered the deciding run to take the loss for the NL West-champion Giants, who have dropped two of their last three.

Aaron Harang started the game for the Dodgers and allowed one run on two hits and two walks over six innings, while Matt Cain, who Giants manager Bruce Bochy named the starter for San Francisco's first playoff game prior to the contest, surrendered two runs on four hits and a walk in a five-inning start.

"68 pitches, that was the plan for Matt," Bochy said about Cain. "He threw well tonight. A solid five innings, that was just enough for him."

Casilla took the mound for the bottom of the ninth and promptly allowed a single to Hanley Ramirez, who was sacrificed over to second by Shane Victorino.

Luis Cruz followed with a single to left field to place runners on the corners and after A.J. Ellis was intentionally walked, Herrera laced a liner to the right side of the infield that deflected off the glove of a leaping Marco Scutaro and into shallow center field, allowing Ramirez to score the game- winning run.

"One of the biggest hits of my career," Herrera said. "I spent 10 years in the minors and this is my first walk-off. This is a dream come true."

The Giants jumped out to a quick lead in their first at-bat when Scutaro worked a one-out walk and rounded the bases two batter later on Buster Posey's double off the wall in left field.

Neither team advanced a runner past first base from there until Ethier followed Mark Ellis' leadoff single in the bottom of the fourth inning with a blast over the center-field wall, giving the Dodgers a 2-1 edge.

Los Angeles failed to add to its lead by leaving runners on second and third in the fifth inning and having a man thrown out at the plate in the sixth before San Francisco tied the game in the eighth as Angel Pagan pulled a one- out double down the first-base line and came home on a Scutaro base hit to left field.

Scutaro moved to second on the play during Victorino's throw to the plate, but Pablo Sandoval struck out and Posey hit a dribbler to the left of the mound to end the inning.

Game Notes

Scutaro extended his career-high hit streak to 18 games ... Dodgers first baseman Adrian Gonzalez went 2-for-4 to extend his hit streak to 13 games ... Los Angeles leads the season series between the teams, 10-6 ... San Francisco hit 1-for-5 with runners in scoring position and left five men on base ... The Dodgers went 3-for-5 with runners in scoring position and stranded eight.