Updated

Los Angeles, CA (SportsNetwork.com) - Dee Gordon hit the go-ahead RBI double in the bottom of the seventh inning, and Los Angeles rallied from an early deficit to post a 6-2 decision over San Francisco in the third test of a four- game series.

Matt Kemp hit a solo homer and knocked in two runs for the Dodgers, who put the brakes on a three-game skid.

Drew Butera and Yasiel Puig also drove in a run each to help Zack Greinke (6-1) snag the win. He worked seven innings, allowing six hits and two runs while fanning eight and walking three.

Hunter Pence and Buster Posey drove in a run apiece for the Giants, who lost for the third time in their last five.

Jeremy Affeldt (0-1) was charged with two runs on three hits in 1 2/3 relief frames. Matt Cain returned from the 15-day disabled list to give up two runs on three hits with four walks and as many strikeouts in five-plus innings.

LA moved ahead in the seventh, picking up two more runs to take a 4-2 edge. Butera stroked a one-out double against Affeldt, moved up on a groundout and scored on Gordon's double. After Jean Machi entered, Puig's ground-rule double scored Gordon.

San Francisco had the bases loaded with two outs in the eighth thanks to a pair of singles and a walk, but Brian Wilson worked out of trouble by retiring Pence on a foul out.

Kemp extended the hosts' lead in the home half, welcoming Juan Gutierrez to the mound by launching his fifth homer of the season to right field. Carl Crawford then singled, stole second, advanced on a groundout and came home on Butera's fly to center for a 6-2 game.

Chris Perez maintained the winning margin with a 1-2-3 ninth inning.

The Giants scored twice in the second inning. Brandon Crawford singled, Brandon Hicks walked and Cain reached on a sacrifice attempt, then after Angel Pagan flied out, Pence's fly to center plated Crawford and Cain came home when Posey followed with a base hit.

Cain was chased in the sixth, as the Dodgers loaded the bases with none out after Gordon walked, Puig dropped a bloop single behind shortstop and Hanley Ramirez walked. Affeldt induced a run-scoring double-play grounder from Adrian Gonzalez but surrendered the game-tying single to Kemp before ending the inning on a Carl Crawford groundout.

Game Notes

Greinke threw 74 of his 112 pitches for strikes ... Posey led all players with three hits ... To make room for Cain's comeback, the Giants placed first baseman Brandon Belt on the 15-day DL with a broken left thumb ... Gordon, Puig and Kemp each collected a pair of hits for the Dodgers.