SAN FRANCISCO (AP) -- Mark DeRosa kept glancing at the out-of-town scoreboard as he sat on the bench for seven innings. By the time he came to bat in the 12th, he'd seen the teams ahead of the Giants all win.
"If we wanted to keep any pulse, we had to win this game," DeRosa said after he hit a game-ending RBI single off second baseman Orlando Hudson 's glove in the 12th inning, giving San Francisco a 3-2 victory over the San Diego Padres on Tuesday night.
"It's a tough situation, we all know that," DeRosa said. "We still want to keep playing hard and never forget we're the defending world champions. I sat there and watched the Braves win, Arizona won and the Cardinals won. We still want to finish strong and show our fans how much we appreciate their support."
DeRosa's two-out drive against Brad Bauch (0-2) just evaded Hudson, allowing Cody Ross to score from third.
Pablo Sandoval and Justin Christian also drove in a run for the Giants, who have won three straight. Ramon Ramirez (3-3) pitched a scoreless inning to get the win.
Jason Bartlett had a two-run double for the Padres, who have lost five of six.
Ross kicked off the Giants' 12th with a leadoff single. He moved to second on a wild pitch and Carlos Beltran was intentionally walked. Sandoval bounced into a fielder's choice before DeRosa recorded his fifth career game-ending hit and first in four years.
"A line drive leap and just off the top of the glove," Padres' manager Bud Black said. "Probably as close as you can get."
Giants starter Matt Cain gave up one run and four hits, struck out six and walked three in 6 1-3 innings. He is 2-3 with a 2.01 ERA in his last eight outings.
"We've been playing relaxed all year," Cain said. "We weren't able to find wins at times but we're going to keep playing."
Cory Luebke struck out eight in six innings for the Padres, yielding two runs and 10 hits. The left-hander is 0-3 with a 4.28 ERA in his last five starts.
The Giants grabbed the lead in the first. Ross led off with a single, moved to third on Beltran's double and scored on Sandoval's base hit.
Sandoval and Brett Pill opened the fourth with singles. After Orlando Cabrera struck out, Christian lined a single into center to give the Giants a 2-0 edge.
"Pablo has been more disciplined up there and calmed down," Giants manager Bruce Bochy said. "He's worked at it. He knows if he doesn't expand the zone he'll be a better hitter."
Javier Lopez came in for Cain with a runner on first. He got pinch-hitter Andy Parrino on a groundout but gave up a double to pinch-hitter Aaron Cunningham .
Guillermo Mota took over for Lopez and Bartlett drilled his first offering to the wall in left-center field, tying it at 2.
"We had other chances along the way and we couldn't get the big hit," Black said. "It's something we've talked about all year."
NOTES: Giants LHP Jonathan Sanchez (ankle) threw off flat ground. ... LHP Jeremy Affeldt is the Giants nominee for the Roberto Clemente Award. ... RHP Mat Latos (7-13, 3.72) pitches for the Padres in the series finale Wednesday. Latos is 2-3 with a 2.89 ERA over his last eight starts. He has a career 1.33 ERA at AT&T Park. ... INF Orlando Hudson is the Padres nominee for the Roberto Clemente Award. ... RHP Tim Lincecum (12-12, 2.68 ERA) starts for the Giants on Wednesday. Lincecum returned to form in a no-decision his last time out, allowing one run and six hits over eight innings. He's 8-4 with a 2.08 ERA in 17 starts against the Padres. ... Giants speedster Darren Ford was picked off at 1B by Chad Qualls in the 8th. ... The Giants are 13-8 in extra-inning games, 21-17 in their last at bat and 32-21 in one-run games.