Hours before the first pitch, the Phillies improved their chances at winning a fourth straight NL East title by acquiring three-time All-Star Roy Oswalt from Houston for J.A. Happ and two prospects.
Oswalt is scheduled to start for the two-time NL champions at Washington on Friday night.
After the Diamondbacks tied it in the ninth, the Phillies rallied against Esmerling Vasquez (1-4) in the 11th.
Vasquez struck out Jayson Werth before Cody Ransom walked. After Carlos Ruiz singled, Valdez lined a single to center and Ransom slid in safely ahead of center fielder Chris Young's throw. The Phillies closed within 2½ games of division-leading Atlanta. They have made up 4½ games in the past week.
Jose Contreras (5-3) tossed a scoreless 11th for the win. Passed over in a save situation in the ninth, closer Brad Lidge pitched a perfect 10th. Lidge struggled while earning two straight saves earlier in the week.
Joe Saunders gave up two runs and nine hits in seven innings in his first start since the Diamondbacks acquired him in the trade that sent Dan Haren to the Los Angeles Angels.
Kyle Kendrick allowed one run and four hits, striking out a season-high five in 6 1-3 innings. He's 1-0 with a 1.35 ERA in two starts since a brief demotion to the minors last week.
Miguel Montero hit a solo homer for the last-place Diamondbacks, who have lost seven straight.
The Diamondbacks rallied to tie it in the ninth, but blew a chance to take the lead. After Ryan Madson tossed a perfect eighth, manager Charlie Manuel kept him in instead of turning to Lidge. But Justin Upton led off with a double and J.C. Romero entered to face Adam LaRoche, who lined a single to right.
Upton scored the tying run on Montero's slow chopper to shortstop. After Mark Reynolds was intentionally walked, Romero walked Stephen Drew on four pitches to load the bases.
But second baseman Placido Polanco and shortstop Valdez turned an outstanding double play on Gerardo Parra's grounder to second. Valdez made a strong throw to barely beat Parra at first. Parra was ejected by first-base umpire Adrian Johnson after slamming his helmet in disgust.
It was the second time Parra hit into a double play in a clutch spot. With runners at first and third and one out in the seventh, Polanco and Valdez made an even better turn on Parra's slow bouncer.
Ibanez gave the Phillies a 2-0 lead in the sixth with a drive into the seats in right-center. Ibanez is batting .391 with two homers and 10 RBIs in the second half, raising his average to .263 from .243 at the All-Star break.
Ransom hit a one-out single in the fifth and scored when Ruiz lined a double into the left-field corner.
Notes: SS Jimmy Rollins sat out his third straight game with a bruised left foot. The Phillies are also missing 2B Chase Utley and CF Shane Victorino. Phillies RF Domonic Brown wasn't in the starting lineup a night after going 2 for 3 with two RBIs in his major league debut. Ben Francisco started instead of the left-handed hitting Brown against the lefty Saunders. Brown got a standing ovation when he pinch-hit in the seventh and flied out. ... Upton extended his hitting streak to 14 games. ... A crowd of 45,232 was the 91st straight sellout at Citizens Bank Park.