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.
Atlanta Braves' Max Fried leaves after one inning with ankle injury
Braves ace and Cy Young Award contender Max Fried injured his ankle fielding a bunt and was forced to leave his final start of the regular season after just one inning.
Ohtani hits two-run homer vs. Padres
Shohei Ohtani cranks a two-run home run to right-center field in the Angels' 5-2 win vs. the Padres.
Clevinger suddenly pulled after 1 inning, Pads fall to Halos
The San Diego Padres might have suffered a blow to the front of their playoff rotation when right-hander Mike Clevinger was suddenly pulled after only one inning in his start Wednesday in a 5-2 loss to the Los Angeles Angels.
Kansas City Royals place Bubba Starling, Kyle Zimmer on IL to end their seasons
The Royals placed outfielder Bubba Starling and right-hander Kyle Zimmer on the injured list and returned left-hander Mike Montgomery and outfielder Franchy Cordero from rehab assignments to set them up for the final five games of the season.
Nats sweep Phils, drop Philadelphia below playoff position
The Philadelphia Phillies tumbled out of a playoff position, getting swept in a doubleheader by the Washington Nationals when Yadiel Hernandez hit a game-ending, two-run homer in eighth inning off Brandon Workman for a 8-7 win in Tuesday night's...
Who has the best rotation for MLB's postseason?
Chipper Jones, Rick Sutcliffe and Jon Sciambi explain why the Reds, Indians and Brewers respectively have dangerous rotations heading into MLB's postseason.