Updated

A.J. Ellis' bases-clearing double in the ninth inning lifted the Los Angeles Dodgers to a 4-1 win over the San Francisco Giants in the rubber match of a three-game set at AT&T Park.

Yasiel Puig opened the inning with a single and Adrian Gonzalez followed with a grounder to Buster Posey at first base. Posey, though, couldn't handle the sharply hit ball and his throw to second sailed into left field allowing Puig to advance to third base.

Hanley Ramirez followed with soft grounder back to Sergio Romo (3-4) for what appeared to be a tailor-made double play, but second base was not covered and Romo was forced to get the out at first, putting a pair of runners into scoring position.

Romo then intentionally walked Andre Ethier before striking out Juan Uribe, but Ellis hammered a hanging slider into the left-field gap to clear the bases.

Kenley Jansen stranded a runner in the ninth to earn his ninth save of the season.

Ethier finished the game 1-for-2 with an RBI and two walks, Ramirez doubled and tripled and also scored a run and Puig added a pair of hits for the Dodgers, who have won 12 of their last 15 games to improve to 42-45.

"We're a confident bunch right now," Dodgers manager Don Mattingly said. "I think we feel like we're going to win when we play a game every day and that's something different then early on. The feeling has definitely changed."

Clayton Kershaw (8-5) dominated Giants hitters over eight innings, giving up just one run on three hits to pick up his third straight win.

Andres Torres drove in the only run for the Giants, who have dropped 11 of their last 13 games.

Giants starter Chad Gaudin, who was reinstate from the 15-day disabled list prior to the game, gave up one run on four hits and one walk while striking out nine over seven innings.

"Overall it was a fairly clean game because of the effort that our starter gave us," Giants manager Bruce Bochy said of Gaudin.

The Dodgers took a 1-0 lead in the second inning. Ramirez tripled then scored on Ethier's base hit to center.

San Francisco tied the game in the third. Guillermo Quiroz doubled, moved to third on a wild pitch then scored on Torres' sacrifice fly to center field.

Game Notes

Ramirez extended his hitting streak to an MLB-best 18 games ... Los Angeles has taken five of its last six games with San Francisco ... Kershaw has held opponents to two runs or less in six of his last seven starts ... With the win, the Dodgers move within 4 1/2 games of the Arizona Diamondbacks for first place in the NL West. Los Angeles opens a four-game set with the D'backs on Monday at Chase Field ... The Giants will open a three-game set with the Mets on Monday.