Evan Meek (1-0) pitched two scoreless innings for the win and Octavio Dotel held on for his second save in two opportunities.
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 first to end the game.
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.
Paul Maholm pitched five-plus innings for the Pirates, yielding three runs and eight hits.
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.
LaRoche homered with one out in the ninth and Iwamura added an RBI single.
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.
NOTES: 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.