SAN FRANCISCO (AP) -- Angel Pagan hoped he would be in the batter's box with a chance to win the game. And, in this case, an opportunity to give the World Series champions some much-needed momentum.
He came through by lining a game-ending double to right field with one out in the ninth inning, and the San Francisco Giants returned from a rough road trip to beat the San Diego Padres 3-2 on Friday night.
Santiago Casilla (2-1) struck out two in a 1-2-3 ninth for the win. Shortstop Brandon Crawford made a great pickup on Jesus Guzman's grounder for the second out.
Luke Gregerson (1-2) gave up Gregor Blanco's leadoff bloop single to shallow left to start the rally, then pinch-hitter Andres Torres reached on a fielder's choice after an unsuccessful sacrifice bunt attempt and stole second before coming home on Pagan's hit. It was Pagan's first game-winning hit since last July 1 against the Reds - also a double.
''It's one of those situations you want to be the guy,'' Pagan said. ''I wanted to be in that situation. I wanted to get the hit. We needed that win after getting swept in Milwaukee.''
Blanco wound up with three hits, Pagan and Brandon Belt with two apiece, and San Francisco had its speedsters together for the winning push.
Hurt by some bad luck on hard-hit balls during the road trip, Blanco vowed to do anything he could to get on base in the ninth.
''Back in Milwaukee I hit the ball several times hard, and today I got two hits with half-swings,'' he said. ''I don't really practice it to tell you the truth. I just try to use my speed.''
So did Torres with the heads-up steal.
''It was huge,'' Pagan said.
Madison Bumgarner struck out a season high 10 and Hunter Pence hit an RBI double for the Giants. Bumgarner struck out 10 or more batters for the ninth time in his career.
Chase Headley hit a tying, two-out homer in the sixth just over leaping left fielder Blanco. The tying run kept Bumgarner from becoming the first Giants pitcher to win his first four starts since Tim Lincecum in 2010.
After San Diego hit three home runs Wednesday against Dodgers ace Clayton Kershaw, Headley's first clout of 2013 gave the Padres home runs in eight of their last nine games. But San Diego had its three-game winning streak snapped on a night it nearly turned a triple play on Bumgarner's double-play grounder in the sixth but the pitcher reached first.
''For a moment I thought it might work,'' Padres manager Bud Black said. ''But Bumgarner gets down the line pretty good.''
Headley also had a first-inning sacrifice fly for San Diego. Buster Posey then added one of his own in the bottom half to tie the game at 1.
Pence's third-inning double scored Posey for the Giants' first lead in 27 innings since their previous advantage in the third inning at Milwaukee on Tuesday. The Giants were swept by the Brewers for a season-high three-game skid.
Thousands of fans in the sellout crowd of 41,559 at AT&T Park were late arrivals on fireworks night because of long lines and extra security that included the use of electronic scanning wands.
In the eighth inning, they were treated to ''Sweet Caroline'' as a tribute to Boston. An American flag waved, and several fans sported Red Sox shirts.
''That's touching, it is, with what's happened there in Boston,'' Giants manager Bruce Bochy said. ''We are certainly thinking of the victims there. It's a tragedy. It's nice to honor Boston and their courage.''
Padres starter Edinson Volquez, the winning pitcher in the semifinals for the World Baseball Classic champion Dominican Republic here last month, allowed two runs in six innings and remained winless in four starts.
Guzman doubled and singled for San Diego, but the Padres' lineup that had previously had success against Bumgarner got shut down. San Diego's active position players came into Friday batting .290 (38 for 131) with 12 doubles, two triples, five homers and 21 RBIs against the left-hander.
Five of the last six Padres losses have been by two or fewer runs and three of those were decided by one run - including three straight.
Crawford went 0 for 4 with two strikeouts to have a career-best 11-game hitting streak snapped along with a 14-game stretch of reaching base safely.
A moment of silence was held both for the Boston victims and the wife of Hall of Famer Willie Mays, Mae Louise Allen Mays, who died in her sleep Friday morning at age 74 following a long fight with Alzheimer's disease.
NOTES: Posey will catch Lincecum on Saturday night, a rarity last season - considering the difficulty of catching the hard-throwing right-hander when Posey had returned from 2011 season-ending left leg and ankle injuries. ''Ready to go,'' Posey said. Added Bochy, ''There's no reason why he wouldn't catch him.'' If needed, Posey could get Sunday afternoon's series finale off. ... Padres RHP Tyson Ross injured his non-throwing shoulder getting his first major league hit vs. Clayton Kershaw on Wednesday. Manager Bud Black said it could affect next start. ''He's sore,'' Black said. ''If you ask Tyson, he thinks he can pitch. He wants to pitch. I wouldn't say it's definite he'll start.'' ... The division rivals met for the first of 19 games. The Giants won last season's series 12-6 and are 25-12 in the matchups over the past two years.