The Diamondbacks scored single runs in the seventh and eighth innings to come from behind, then held on in the ninth after an error by first baseman Paul Goldschmidt came close to costing them the game.
Arizona won its fifth in a row, battling back after Philadelphia took a 2-0 led in the first.
Hernandez came on in the ninth to protect the one-run cushion, but Goldschmidt's fielding error allowed leadoff hitter Domonic Brown to reach base.
Brown moved to second on a single by John Mayberry and both runners advanced on a sacrifice by Ben Revere.
Tony Sipp (2-1) recorded the final two outs in the eighth inning to become the winning pitcher.
Celebrity Families of 2014 [PHOTOS]