By Sam Bush

The Phillies were starting to look like toast again in the desert last night.

They had gotten to the 8th inning hanging onto a 1-0 lead the feeling in the stands was that they would waste another stellar pitching performance, just as they had Monday night.

But Nick Pivetta threw six scoreless innings, Nick Williams homered and the Phils beat the Diamondbacks 5-2.

Pivetta (7-9) scattered five hits, struck out six and walked one to get his first win in four starts.

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.

Zack Greinke (12-7) allowed only Nick 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.

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.

Asdrubal Cabrera’s bases-loaded double off Diekman brought in two more runs and Jorge Alfarohad an RBI single against reliever Brad Ziegler.

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.

Greinke settled down from there.

But Arizona could get nothing going against Pivetta.

A.J. Pollock and Escobar opened the Diamondbacks’ fourth with singles before Steven Souza Jr. grounded into a double play. Pollock was stranded at third when Ketel Marte flew out to center.

The Diamondbacks’ Nick Ahmed hit into double plays to end the second and seventh.