SAN DIEGO -- David Peralta hit a leadoff homer and added a go-ahead double in the seventh for the Arizona Diamondbacks, who scored 11 runs in the final four innings and overcame Hunter Renfroe's three homers as the NL wild-card leaders beat the San Diego Padres 13-7 on Wednesday night.
The Padres, who blew a 6-2 lead, hit five home runs. Renfroe had his first career three-homer game and tied Nate Colbert's club record for rookies with 24. Renfroe became the first Padres rookie to hit three home runs, and the seventh San Diego player overall to do it.
The Diamondbacks, who cut their magic number to four for clinching their first postseason berth since 2011, hit four homers in avoiding a three-game sweep. They scored four times in the sixth to tie it, including a two-run homer by J.D. Martinez, and went ahead in the seventh. Chris Herrmann singled with one out off Craig Stammen (2-3) and scored the go-ahead run on Peralta's double to center.
A.J. Pollock hit a three-run homer in the four-run ninth, his 13th. All four runs were unearned due to an error by shortstop Erick Aybar.
The Diamondbacks' first three home runs were off rookie starter Dinelson Lamet. Martinez's two-run shot in the sixth pulled them into a 6-all tie after they trailed 6-2. It was his 24th with the Diamondbacks and 31st overall.
Peralta homered to left-center on the game's second pitch, his 14th, and Jake Lamb connected with one out in the second, his 28th.
Jimmie Sherfy (2-0) pitched one inning for the win.
Rocky Gale and Christian Villanueva hit their first career home runs for San Diego.
The five homers gave the Padres 181, setting a franchise single-season record. They have a record 85 at Petco Park this season, breaking the old mark of 83 set last year. The downtown ballpark opened in 2004.
Villanueva, who made his first big league start Monday night, got his first hit when he singled with one out in the second. Gale, 29, who's spent almost his entire career in the minors, followed with a two-run homer off the lower balcony on the Western Metal Supply Co. brick warehouse in the left-field corner. He had a big smile on his face as he rounded the bases.
Gale also was called up Monday. He's making his first appearance in the big leagues since 2015, when he played in 11 games with the Padres. He had made one previous start, on Sept. 30, 2015, when he got his first and, until Wednesday night, only major league hit.
Renfroe hit a two-run homer in the third, a leadoff shot in the fifth and a solo drive in the ninth. It was the fourth career multihomer game for Renfroe, who made his big league debut late last season, and his third this year. He was recalled Monday from Triple-A El Paso, where he'd spent a month working on his swing.
Lamet allowed six runs and six hits in 5 1/3 innings, struck out four and walked one.
Diamondbacks: After a day off, RHP Zack Greinke (17-6, 2.87 ERA) is scheduled to start the opener of a three-game home series against Miami on Friday night. He is 3-0 with a 1.56 ERA in his last six games.