Jose Tabata's three-run double capped the big rally.
After St. Louis beat Atlanta earlier in the day, Pittsburgh needed a win to keep the division lead.
Garrett Jones and Jordy Mercer hit solo homers for the Pirates.
Jeanmar Lopez (3-0) got the win. Guillermo Moscoso (1-2) took the loss.
Marco Scutaro and Brandon Crawford each had two RBI for the Giants, losers of four of their last five games.
Couple mistakenly served bag of cash at McDonald's drive-thru
Gal Gadot cast as Wonder Woman for 'Batman vs. Superman'