SAN FRANCISCO -- Garrett Jones started the game as Pittsburgh's offensive star. He ended it as an unlikely defensive hero.
"That's not the way I had it planned but it worked out," Dotel said.
Eugenio Velez hit a two-run homer off Dotel in the ninth but the closer responded by retiring three straight, getting Pablo Sandoval to line out to the 6-foot-5 Jones, three inches taller than starter Jeff Clement, to end the game.
"That was a great play," Pirates manager John Russell said. "The reaction on that ball was really good. It was hit hard; a nice way to end the game."
Jones said he had trouble picking up the ball off Sandoval's bat.
"That was a shot," said Jones, who moved into the infield late in the game. "I just barely saw it off the bat and I just had to get the full extension and luckily it went right in the glove."
Matt Cain allowed three runs and five hits in six innings for the Giants, who lost for just the second time. Cain retired the last 10 batters he faced.
"I was happy with how I ended," he said. "Mechanically I was trying to find some things early and getting myself into trouble. I put the guys in a hole through the first three and they did a great job of battling back."
Paul Maholm pitched five-plus innings for the Pirates, yielding three runs and eight hits.
"I never got into a perfect rhythm but that lineup is a challenge," Maholm said. "There are no easy outs; even Cain has a couple of hits off of me so it wasn't like I was extremely comfortable."
Pittsburgh went in front for good in the eighth. With one out and a runner on first, Lastings Milledge hit a comebacker to Jeremy Affeldt but shortstop Edgar Renteria couldn't handle the throw to second. Jones then grounded a single into right field to give the Pirates a 4-3 lead.
"That's an aberration more than anything," Giants manager Bruce Bochy said of Renteria's error. "It's not something you're going to see too often. It just didn't stick in his glove."
LaRoche homered with one out in the ninth and Iwamura added an RBI single.
"We definitely needed that after a couple of tough losses," Jones said. "We got some big hits when we needed them and scored just enough to win."
The Giants rallied after falling behind 3-0 in the third. Sandoval had an RBI single in the bottom half, Mark DeRosa added a run-scoring double in the fifth and Velez drove in the tying run with a groundout in the sixth.
Sandoval's single in the third extended his hitting streak to 12 games dating to last year. ... The Pirates stole two bases and have yet to be caught in 10 attempts. ... Maholm is 0-1 with a 4.30 ERA in four starts at AT&T Park. ... Meek has not allowed a run in San Francisco in four appearances (4 2/3 innings). ... Giants C Bengie Molina reached base safely in nine straight plate appearances before striking out in the eighth. ... Ryan Church's triple in the ninth for Pittsburgh was his first since April 26, 2008, against the Atlanta Braves.
New York Yankees' Aroldis Chapman dealing with Achilles issue as runs allowed streak stretches to five straight appearances
Aroldis Chapman says he's dealing with a left Achilles issue but refused to blame to that for his recent struggles, the latest a blown save against the White Sox on Sunday.
Adele, Christian McCaffrey among stars enjoying live sporting events
Another night, another celebrity sighting at a live sporting event.
Chicago White Sox star Tim Anderson hushes booing New York Yankees fans with home run in win
Tim Anderson hit a three-run homer and then put a finger to his lips to silence the booing fans, capping a tumultuous weekend at Yankee Stadium and helping the Chicago White Sox beat New York 5-0 Sunday night for a doubleheader sweep.
Anderson's HR hushes Yankees, lifts Chisox to twinbill sweep
— Tim Anderson said everything he had to say with one swing of the bat — and a commanding trot around the bases.
Anderson shushes Yankees fans after homer in 8th
Tim Anderson smacks an opposite-field, three-run homer in the eighth inning to widen the White Sox's lead.
New York Mets, Chris Bassitt reach 1-year, $8.65 million deal with $19 million mutual option for 2023
The Mets and pitcher Chris Bassitt agreed to a one-year, $8.65 million deal with a $19 million mutual option for next year to avoid an arbitration hearing.