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.
Video of Victoria’s Secret models trying to 'twerk' hits Instagram
Wisconsin business offering 'therapeutic cuddling' forced to close