PHOENIX -- Arizona shortstop Didi Gregorius could not have picked a better way to break out of a prolonged slump Saturday.
Gregorius's three-run home run with one out in the eighth inning broke a tie at 2 and helped the Diamondbacks to a 5-2 victory over the San Diego Padres on Saturday at Chase Field.
"I was just trying to put a ball in play and get at least one or two runs right there," Gregorius said. "I hit a line drive and it went out. I'll take it."
Gregorius was 2-for-39 entering his at-bat in the eighth, but one of those hits was a two-run homer at Washington on Monday. He has six homers this season.
"I would say about time," Gregorius said with a smile. "I've been working, getting better, going down in the cage every day, just trying to make improvements."
Arizona third baseman Jake Lamb hit his first major league homer in the second inning, and his one-out single off Kevin Quackenbush (2-3) after a walk to left fielder Alfredo Marte brought Gregorius to the plate in the eighth.
"Just go at-bat by at-bat don't worry about it," Gregorius said of his dry spell. "I can't change it. Just go out and play the game. Don't drag one at bat to the next one."
Arizona left-hander Oliver Perez (3-3) gave up a game-tying two-run single to Padres third baseman Yangervis Solarte before stranding runners at first and second in the top of the eighth inning.
Rookies Lamb and center fielder Ender Inciarte had two hits apiece for the D-backs (55-75), who have won two in a row after a six-game losing streak.
Addison Reed pitched a 1-2-3 ninth inning for his 30th save.
Diamondbacks left-hander Vidal Nuno held the Padres to two runners, on a hit and a walk, before he hit Padres right fielder Rymer Liriano to open the eighth inning. Center fielder Cameron Maybin singled and shortstop Alexi Amarista walked to load the bases before and Perez entered to face Solarte.
Nuno, 0-3 with a 3.72 ERA, has not won in nine starts since being obtained from the New York Yankees, extending a franchise record drought for a starter.
"It's part of the game," Nuno said. "I just try to go deep in ball games. I've just been unlucky. I'll keep on fighting, and one day I'll get it."
Maybin had two of the Padres' three hits. San Diego (59-69) has lost three in a row and five of its last six.
Quackenbush had his first major league save Wednesday and had not given up a run in his last 6 2-3 innings before Gregorius's game-deciding homer.
"Players are not perfect," San Diego manager Bud Black said. "They are not invincible. He has been pretty good for us all year. We trust him. The ups and downs for a major League relief pitcher, especially for a guy who pitches late in the game, a night like tonight, he will learn from it."
Quackenbush had given up one homer in his previous 39 1-3 innings this season.
Padres right-hander Andrew Cashner gave up two runs and seven hits in five innings in his first start since June 18.
Inciarte doubled to lead off the first inning and scored on second baseman Cliff Pennington's single between first and second base to give the Diamondbacks a 1-0 lead.
Enciarte has hit safely in 31 of his last 35 starts, and Pennington has a hit in eight of his last 10 starts.
Lamb hit his first career home run to lead off the second inning for a 2-0 lead.
"The first inning I thought I was a little too excited, a little too amped," Cashner said. "I thought I competed well. I didn't feel that I commanded anything but I gave us a chance to win.
"I am a better pitcher than the way I showed tonight but it was definitely a step in the right direction.
NOTES: San Diego 2B Jeff Gyorko was held out of the starting lineup Saturday because of a left hamstring injury he first felt Thursday against the Dodgers, Padres manager Bud Black said. "It just tightened up and he kept playing," Black said. "It truly is day to day." Gyorko struck out as a pinch-hitter with the bases loaded and one out in the eighth inning. ... Arizona leads the majors with 36 outfield assists, five more than Minnesota and Oakland. Rookie CF Ender Inciarte has eight and since-traded RF Gerardo Parra also has eight. ... LHP Frank Garces was optioned to Double-A San Antonio to make room for Saturday starter RHP Andrew Cashner on the Padres' 25-man roster. Cashner was activated before the game. ... San Diego manager Bud Black's next victory will be the 600th of his managerial career. He is second in Padres history behind current San Francisco manager Bruce Bochy, who had 951 with San Diego.