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.
Twins' Miguel Sano out after cutting foot celebrating Dominican title
Twins third baseman Miguel Sano will miss at least the first week of full-squad workouts after he cut his foot while celebrating his team winning the Dominican Winter League championship.
Remembering Dodgers legend Newcombe
Tony Kornheiser and Michael Wilbon pay homage to Dodgers pitching great Don Newcombe, who died at 92.
Rob Manfred: Slow free-agent market may be 'much ado about nothing'
Hours after Manny Machado agreed to a $300 million, 10-year deal with San Diego, MLB commissioner Rob Manfred said the slow free-agent market is "a little much ado about nothing if in fact those players all sign at the end of the day."
Cardinals' Carlos Martinez shut down, to be re-evaluated March 5
Cardinals pitcher Carlos Martinez, who had an MRI this week that showed his right shoulder is structurally sound, will be shut down for two weeks and be re-evaluated March 5.
Machado deal accelerates Padres' path back to the postseason
A team spending to win? The third baseman's move to San Diego changes the prospect-packed Friars' timetable for a return to contention.
Why Manny Machado's record deal makes sense
By signing the biggest free-agent deal in sports history, both the player and the Padres knew exactly what they were doing.