Hamels (5-5), who yielded just a run on six hits, showcased his best stuff on Thursday. His fastball topped out nearly 2 m.p.h. faster than his average and all of his pitches were sharp, keeping the Giants off-balance for most of the afternoon.
The 30-year-old lefty has gone at least seven innings in 13 of his last 15 starts.
Jonathan Papelbon made amends for Wednesday's loss, pitching a 1-2-3 ninth to secure the game and his 24th save.
Tim Hudson (8-7) took the hard-luck loss despite surrendering just a pair of unearned runs with six strikeouts through six innings.
The Phils wasted no time getting to Hudson, as Jimmy Rollins reached on a bloop double with one out in the first inning and moved to third on a passed ball. Two batters later, Byrd knocked him in with a single to left to give the home team an early 1-0 advantage.
The Giants briefly tied things in the top of the fifth before Philadelphia went back in front in the home half. Ehire Adrianza laced a liner past a diving Rollins into center field with two outs, easily plating Gregor Blanco as Ben Revere's throw to the plate was cut off.
Revere led off the home fifth by reaching on Michael Morse's dropped fly in left. After Rollins went down swinging, Utley's single up the middle scored the speedy Revere.
Papelbon took the field in the ninth to a chorus of boos from the home crowd, but got Adam Duvall to pop up in foul territory. Joaquin Arias then struck out swinging and Blanco lined to Grady Sizemore in left to end the contest.