LOS ANGELES -- Two runs in the 10th inning lifted the San Francisco Giants to a 3-1 victory over the Los Angeles Dodgers on Thursday night at Dodger Stadium.

Pinch-hitter Hector Sanchez drove in center fielder Angel Pagan, who drew a one-out walk and advanced to third on consecutive walks to right fielder Hunter Pierce and catcher Buster Posey, with a sacrifice fly to right with one out.

An RBI single by first baseman Brandon Belt scored Pence for the game's final run as the Giants (22-13) ended a two-game skid and handed the Dodgers (19-17) their fourth defeat in five games. The Giants took five of seven contests from Los Angeles.

Reliever Santiago Casilla (1-0) struck out two in 1 1/3 innings. Closer Sergio Romo collected his 11th save with a scoreless 10th. Dodgers left-hander J.P. Howell (1-3) allowed a run on a hit in 1/3 of an inning.

Brandon Hicks drove a 1-0 pitch from Dodgers starter Josh Beckett into the bleachers in left for a solo home run to tie the score at 1 with one out in the seventh inning. It was the sixth homer for Hicks.

After pitcher Ryan Vogelsong grounded out, Pagan hit a two-out double to left to chase Beckett.

Beckett, who is winless in his past 14 starts, allowed a run on five hits in 6 2/3 innings. He struck out four and walked one on 107 pitches (66 strikes). Beckett hasn't won a decision since Sept. 30, 2012, when he beat the Colorado Rockies at Dodger Stadium. Entering Thursday's game, he was 0-6 with a 4.38 ERA in his last 13 starts.

Vogelsong worked 7 1/3 innings, allowing a run on five hits with two strikeout and two walks. He threw 104 pitches (64 strikes).

Los Angeles third baseman Juan Uribe left the game with mild hamstring soreness.

Vogelsong retired the first 10 batters he faced before giving up a fourth-inning single to right fielder Yasiel Puig on a hard-hit grounder than shortstop Brandon Crawford was unable to handle.

Vogelsong also doubled off the wall in left to lead off the fifth, but he was stranded at second as Beckett retired the next three batters.

The Dodgers broke the scoreless tie in the fifth. Center fielder Matt Kemp singled, advanced to second on a walk to left fielder Carl Crawford, went to third on Juan Uribe's flyout to right, then scored on a sacrifice fly to center by catcher Drew Butera.

NOTES: Giants RHP Matt Cain will start Saturday's contest against Dodgers RHP Zack Greinke. Cain (0-3) missed two turns in the rotation after cutting his right index finger making a sandwich. Cain, who has gone at least five innings in each of his five starts, had a rough outing last time he pitched at Dodger Stadium, when he allowed five runs on six hits in six innings in a 6-2 loss April 6. ... Andre Ethier was the odd man out of the Dodgers' outfield rotation, giving way to LF Carl Crawford, CF Matt Kemp and RF Yasiel Puig. ... Dodgers 1B Adrian Gonzalez celebrated his 32nd birthday.