With the game tied 4-4 and none out in the seventh, Pagan blasted a 3-2 pitch from Sean Henn (0-1) deep into the left field bleachers for the decisive blow.
The Giants center-fielder finished 3-for-3, adding an RBI triple and run-scoring single, as San Francisco took the opener of a three-game series.
Petit (4-0) allowed four runs on seven hits over six innings, walking three and striking out one to get the decision.
Eric Young Jr., Daniel Murphy, Wilmer Flores and Matt den Decker provided one RBI apiece for New York.
Notable deaths of 2014 [PHOTOS]
Julius Randle breaks leg during NBA debut