PHOENIX -- Add Nick Pivetta's Tuesday night performance to the long list of quality outings by Philadelphia starters this season.
Pivetta (7-9) scattered five hits, struck out six and walked one to get his first win in four starts.
"The guys really picked me up on defense," he said, "and we scored runs when we really needed them. I think the team really pulled together and made this happen today."
Pivetta had gone 2-6 in his 10 previous starts since June 1.
"I think the organization has continued to show a great deal of confidence in Nick Pivetta," Phillies manager Gabe Kapler said, "and this is Nick kind of rewarding the organization for its patience."
The Phillies, who blew a 2-0 lead in the ninth inning and lost 3-2 in 14 in a 4-hour, 38-minute game on Monday, led 5-0 after a four-run eighth.
"We know how to take a punch," Kapler said. "We took a punch last night and it was a hard one, but we bounced back again today. It is sort of the character of our club now. We get knocked down but we pop right back up."
Zack Greinke (12-7) allowed only Williams' solo homer on three hits in seven innings but lost his second straight, despite giving up a combined three runs in the two outings. He'd gone 7-0 in his previous eight starts. Greinke struck out four and matched his season high with four walks.
"It was all right," he said. "A little wild early and it got better as the game went on. I felt good the whole time but I just wasn't hitting the spots early."
Philadelphia is up by 1 1/2 games on Atlanta in the NL East and Arizona dropped out of first in the NL West, a half-game behind the Los Angeles Dodgers.
"Last night, that one hurt really bad," Williams said. "But it's baseball, you know."
The Phillies scored their second run on a bunt by Cesar Hernandez leading off the eighth when Arizona reliever Jake Diekman threw the ball away at first and, backing up the play, right fielder Steven Souza Jr. threw wildly to third.
It was uncharacteristic for an Arizona team that leads the majors with a .990 fielding percentage.
"Things broke down on us I the eighth inning," Diamondbacks manager Torey Lovullo said. "I know it wasn't pristine. We play a good brand of baseball here and we are going to address some of those concerns and make sure we don't do it again."
Pat Neshek pitched a scoreless ninth for his second save.
Paul Goldschmidt doubled in a run and another scored on third baseman Maikel Franco's fielding error in the eighth for Arizona but Eduardo Escobar grounded into the Diamondbacks' fourth double play of the night to end the inning.
Greinke, who had 25 walks all season entering the game, walked two in each of the first two innings and escaped both times.
But Williams hit the first pitch of the third just over the right field fence to put the Phillies up 1-0.
"I wasn't looking for a certain pitch," Williams said. "I was just looking for something up."
Greinke settled down from there.
But Arizona could get nothing going against Pivetta.
The Diamondbacks' Nick Ahmed hit into double plays to end the second and seventh.
Phillies: INF J.P. Crawford (broken left hand) could be activated for Wednesday's series finale, manager Gabe Kapler said, or the team could wait until after Thursday's off day.
Diamondbacks: CF Pollock was back in the lineup after two days off to rest his tired legs. Pollock made pinch-hit appearance in both of those games.
How the Phillies can be smart spending stupid amounts of money
The Phillies have plenty of payroll space and expectations of contention to deliver on. Here's a plan for which top free agents they should target.
Buster's Buzz: A checkup on the state of baseball
A new TV deal and strong attendance don't jibe with complaints about the changing game. What are the strongest indicators of the sport's health?
Astros acquire Aledmys Diaz in trade with Blue Jays
The Astros, who could lose Marwin Gonzalez to free agency, acquired infielder Aledmys Diaz, who hit a career-high 18 homers last season, in a trade with the Blue Jays.
Dodgers closer Kenley Jansen set for Nov. 26 heart surgery
Dodgers closer Kenley Jansen is expected to be ready for spring training after surgery to correct his irregular heartbeat. The surgery, which had been expected, has been scheduled for Nov. 26, with recovery time anywhere from two weeks to eight weeks.
Red Sox re-sign Series MVP Steve Pearce on 1-year, $6.25M deal
World Series hero Steve Pearce will be back in a Red Sox uniform in 2019. Boston re-signed the journeyman 1B for a reported $6.25 million. "We all saw what kind of impact he can have," GM Dave Dombrowski said of the improbable World Series MVP.
Rangers hire Julio Rangel to handle pitching staff
Julio Rangel has been hired by the Texas Rangers as pitching coach for new manager Chris Woodward.