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.
Google buys drone maker Titan Aerospace
Pistorius testifies he didn't consciously pull trigger when he shot girlfriend