LOS ANGELES -- The numbers game figured into the San Francisco Giants' favor again.

Two runs in the 10th inning lifted the Giants to a 3-1 victory over the Dodgers on Thursday night before a crowd of 43,068 at Dodger Stadium.

"We just played very well and pitched great baseball and found a way to get it done," San Francisco manager Bruce Bochy said. "We played crisp, very sharp tonight."

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 deep right with one out off reliever Jamey Wright, who struggled with his control.

Sanchez said his approach was simple.

"Hit a fly ball and get the run in," Sanchez said. "This guy came in throwing balls but I had to be ready for that pitch in that situation. It's my job. I have to always be ready."

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. At Dodger Stadium, San Francisco has captured six of the last seven contests.

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.

"They've got a good club," Dodgers manager Don Mattingly said. "We know who they are. We knew they were going to be tough."

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).

"Good to see (Vogelsong) throwing the way he has been in back-to-back games," Bochy said. "Just really hitting his spots, changing speeds, going in and out. He was very sharp and confident."

Said Vogelsong, "Just trying to throw pitches. (Posey) called a good game, just trying to hit his glove. Wasn't trying to overthink it. Just tried to stay with what I've been working on mechanically."

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.

"I was just trying to keep the ball down and be aggressive early," Vogelsong said. "Trying to get quick outs. Just trying to command the ball and keep it simple."

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.

Uribe left the game with mild hamstring soreness.

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.