Buster Posey led off the bottom of the ninth inning with a homer against Ronald Belisario to give the San Francisco Giants a 2-1 win over the Los Angeles Dodgers.
Posey tied the game with an RBI double in the sixth inning, and he won it by taking a 3-2 pitch from Belisario (2-3) over the wall in left field for his first career walkoff homer.
"He's been tough on Buster. He got a pitch he could handle and got the head out," Giants manager Bruce Bochy said. "That's another great comeback for us."
The Giants mustered just four hits in the opener of this three-game series, but received five-plus solid innings from Barry Zito. The lefty scattered six hits and gave up a run while walking four.
Clayton Kershaw, who was activated from the bereavement list to make the start, gave up three hits and fanned five over seven innings.
San Francisco used five relievers with Sergio Romo (2-2) throwing the top of the ninth to get the win.
The Dodgers, who had 11 hits to just four for the Giants, went 3-for-14 with runners in scoring position and left 13 men on base.
Dodgers shortstop Hanley Ramirez left the contest in the sixth inning with an injured left hamstring. Ramirez was thrown out trying to go from first to third on a single to right field by A.J. Ellis. Ramirez was thrown out at third base and he then immediately grabbed for his hamstring.
Ramirez was eventually assisted off the field into the dugout and was replaced by Justin Sellers.
"It's not like he's going to be back in a couple of days," Dodgers manager Don Mattingly said of Ramirez's injury.
Ellis was tagged out at home on a grounder to first baseman Brandon Belt in the second inning.
Kershaw doubled to left field in the fifth inning and went to third on a bunt before scoring on Nick Punto's bouncer into left field.
The Dodgers wasted a bases-loaded chance in the sixth. Chad Gaudin replaced Zito and escaped the jam when Kershaw grounded out.
Kershaw carried a no-hitter into the sixth inning, but it was broken up by Marco Scutaro's triple to center field. With two outs, Posey doubled to right- center. Posey then tried to score on Hunter Pence's single to center, but Matt Kemp made a perfect throw to the plate.
The Giants activated pitcher Jeremy Affeldt from the 15-day disabled list. He had been out since mid-April with a right oblique strain ... In other moves, San Francisco recalled outfielder Francisco Peguero from Triple-A Fresno and also optioned catcher Hector Sanchez to Fresno ... The Giants have 10 come-from-behind wins this season.