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.
Kershaw, Dodgers set for Trout, Angels
The Los Angeles Dodgers will begin a three-game series against the Los Angeles Angels in Anaheim, Calif., starting Friday night, hoping to get a couple of their key lefties on the right track.
Diamondbacks on roll heading into series with Padres
A series win in Colorado, in which they scored 32 runs in three games, has given the Arizona Diamondbacks a much-needed jolt of confidence as they get set to open a three-game set Friday with another winning team in their own division, the San Diego...
Red-hot Cubs aim to keep Brewers in a slump
The Chicago Cubs will look to build upon the best record in the major leagues when they take on the visiting Milwaukee Brewers on Friday night in the second installment of a four-game series.
Cole going for 20th straight win as Yankees face Red Sox
Gerrit Cole's first taste of the rivalry between the New York Yankees and Boston Red Sox is also an opportunity for him to get into the rarified air of pitchers to win 20 straight decisions.
Pirates hope to rough up another Reds pitcher Friday
After the Pittsburgh Pirates roughed up one of the Cincinnati Reds' top starting pitchers Thursday, they'll take aim at another.
Phillies hoping to get rolling as Mets arrive
The struggling Philadelphia Phillies will look to snap a three-game losing streak when they host the New York Mets on Friday.