PHILADELPHIA -- The music is blasting and the Philadelphia Phillies are having fun again. There's plenty to celebrate these days.
It was the fifth win in six games for the Phillies, who have won four of those contests in their last at-bat, including the last three.
"Anytime you have walk-off [wins], it creates excitement and right now it's carrying over to the next day," Phillies interim manager Ryne Sandberg said.
The music blared in the Philadelphia clubhouse following the game -- something that hasn't been the case for most of this disappointing season.
"We're playing together and having fun in here, being able to go out on the field believing in each other," Philadelphia left-hander Cole Hamels said. "We're taking that direction and have to keep pushing in that direction as long as we possibly can."
Cody Asche led off the ninth with a single and went to third on Jimmy Rollins' single. Heath Bell (4-2) intentionally walked Michael Young to load the bases for Kevin Frandsen. After striking out Frandsen, Bell was lifted for left-hander Eury De La Rosa.
De La Rosa ran the count to 3-2 and Utley walked when the final pitch appeared to be a bit inside.
"We were trying to work both sides of the plate," Diamondbacks catcher Tuffy Gosewisch said. "The last pitch started out, then came in and barely missed."
Darin Ruf homered for the second straight game for Philadelphia, which improved to 5-3 under Sandberg. Ruf has eight homers and 12 RBI in 21 games this month.
Matt Davidson had two hits and an RBI for the Diamondbacks, who have dropped four of five, damaging their fleeting playoff hopes. They stayed seven games back of the Reds for the second NL wild-card spot.
"They just got it done in the ninth," Arizona manager Kirk Gibson said.
Jonathan Papelbon (4-1) pitched a scoreless ninth for the win.
The Phillies jumped to a 1-0 lead on Ruf's two-out homer in the second. The Diamondbacks answered with three runs in the fourth off hard-luck Hamels.
Paul Goldschmidt was credited with a double after left fielder Domonic Brown lost his routine fly ball in the lights as twilight fell. Martin Prado drove in Goldschmidt and Adam Eaton with a two-run double, and Davidson's RBI single put Arizona ahead 3-1.
"We got a big break on the ball lost in the lights, but we couldn't tack on," Gibson said.
That was it for the Diamondbacks against Hamels, who allowed six hits and walked one in seven innings. The left-hander has a 1.89 ERA in his last five starts but just one win and four no-decisions over that stretch.
Hamels, who entered with the fifth-lowest run support average among starters in the majors (3.30), remained 5-13 on the season.
"Ultimately, you don't want it to come down to the last at-bat, but winning is winning," Hamels said. "I'm glad we're able to battle and stay with it. It's a good feeling to have something going the right way."
The Phillies threatened in the eighth against Bell, putting runners on first and second with two outs. But Bell struck out John Mayberry Jr. swinging to end the inning.
The Diamondbacks got a runner to second with two outs in the ninth off Papelbon, but Cliff Pennington flew out to center to end the threat.
Arizona's J.J. Putz dislocated his pinky finger in the seventh inning trying to field Rollins' grounder to shortstop. Putz will be placed on the disabled list on Saturday.. Ruiz went 2 for 4, raising his average to .600 (12 for 20) in his last six games.. The three-game series resumes Saturday night when Phillies RHP Ethan Martin (2-2, 5.23 ERA) opposes RHP Randall Delgado (4-4, 3.82 ERA). ... The Phillies wore maroon and white pinstriped uniforms similar to what the club wore in the 1990s on '90s night. ... Frandsen snapped an 0-for-17 skid with a sixth-inning single.