Hamels (3-1) gave up a leadoff double to Willie Bloomquist in the first, then retired the next 18 batters.
The left-hander allowed two runs and four hits. He struck out seven, including his final three hitters.
Hamels' single capped a five-run sixth inning. The Phillies won consecutive games to salvage a 5-5 record on their now-completed road trip.
The Diamondbacks have lost seven of nine. Trevor Cahill (1-2) gave up four runs and six hits in 5 1-3 innings.
Placido Polanco went 3 for 3 with two walks and scored twice. Carlos Ruiz also had three hits for the Phillies.
Philadelphia took a 1-0 lead in the first when Polanco singled, went to second on a passed ball and scored on a sharp single by Hunter Pence.
The Phillies broke it open in the sixth. Juan Pierre singled, Polanco walked and Cahill's second wild pitch of the game scored a run. Pence hit an RBI single that finished Cahill, Ruiz had an RBI single off Craig Breslow and Hamels looped a two-run single for a 6-0 lead.
Consecutive one-out singles in the seventh by Aaron Hill, Justin Upton and Jason Kubel ended Hamels' shutout bid. Hamels walked Cody Ransom to reload the bases and Paul Goldschmidt hit what appeared to be an inning-ending, double-play grounder to shortstop, but second baseman Pete Orr dropped a toss and let a run score.
Hamels induced another grounder off the bat of A.J. Pollock, which did lead to a double play.
NOTES: Phillies 1B Ty Wigginton had a pinch-hit single in the sixth to extend his hitting streak to 11 games. ... Phillies RHP Michael Schwimer, recalled from Triple-A Lehigh Valley when Michael Stutes was placed on the 15-day disabled list, made his season debut in the ninth. ... The Diamondbacks failed to hit a home run at home against the Phillies for the first time in their past 18 games. ... Phillies SS Jimmy Rollins didn't start but came on as a defensive replacement in the bottom of the eighth. Rollins is in the midst of a 3-for-33 slump and is hitless in his past seven at-bats. ... The Chase Field roof was closed for just the second time in 13 home dates with hazy, overcast skies and 90-degree temperatures outside. ... After a day off Thursday, LHP Joe Saunders will take the mound for the Diamondbacks in Miami and face RHP Carlos Zambrano. Saunders is 1-1 with a 1.29 ERA, having allowed three earned runs - four overall - on 21 innings across his first three starts. ... The Phillies also have Thursday off and will send RHP Roy Halladay to the mound against Chicago LHP Paul Maholm at home Friday. Halladay has allowed five runs in 30 innings over four starts for Philadelphia.