Hamels (11-4), making his 100th career road start, scattered six hits and had seven strikeouts in his first win in three career outings at Coors Field. He was 0-1 with an 8.38 ERA at Colorado's hitter-friendly park coming into the game.
Antonio Bastardo finished up with a 1-2-3 ninth.
Drew Pomeranz (1-4) went five innings and allowed five runs on five hits in taking the loss. He struck out five and walked two.
After dropping the opener, the Phillies took consecutive games from the Rockies for their first series victory since June 19-21, when they also took two of three from the Rockies at Citizens Bank Park.
The Phillies were winless in their previous five series against Tampa Bay (1-2), Pittsburgh (2-2), Miami (0-3), the New York Mets (1-2) and Atlanta (0-3).
Up 2-0, the Phillies pulled in front 5-0 in the fifth when Pence connected for his team-leading 17th homer.
Jimmy Rollins hit a two-out single and took second on an errant pickoff throw by Pomeranz before Shane Victorino drew a walk. Pence worked the count against Pomeranz to 2-2 and then jumped on a 79 mph curveball he sent 20 rows deep into the left field bleachers.
The Rockies, who hadn't had a base runner reach second since Dexter Fowler led off the bottom of the first with a single and advanced on a sacrifice, broke up Hamel's bid for a fifth career shutout in the sixth inning.
Hamels issued a one-out walk to Marco Scutaro, his only one of the day, and Carlos Gonzalez followed with an RBI triple that went to the wall in left-center field. Hamels prevented further damage by striking out Ramon Hernandez and getting Michael Cuddyer to ground out.
Victorino got the Phillies' offense going in the first by tripling to center. One out later, Carlos Ruiz brought him home with a single to left. The Phillies got another run in the fourth when Ruiz doubled, moved to third on Ty Wigginton's groundout and scored on Placido Polanco's sacrifice fly.