Paul Goldschmidt's second career walk-off homer put him into the Arizona record books.
The slugger will next try to lead the Diamondbacks to a fourth straight win when they resume a three-game series on Saturday night against the New York Mets.
After the Mets rallied for a pair of runs in the top of the eighth inning to tie the game, Goldschmidt ripped a game-winning solo homer in the ninth to give the D'backs a 5-4 victory.
Goldschmidt, who hit 20 homers and drove in 82 runs in 145 games last season, moved into a tie for the NL lead with 27 homers this season and is tops in the league with 91 RBI through 113 contests. His 27 homers are also the most for a first baseman in club history, passing the 26 hit by Tony Clark in 2005.
"It was fun," Goldschmidt said. "You get an opportunity to win the game in the ninth inning or extra innings ... and it's a lot of fun. Hopefully we can do it a few more times."
Goldschmidt's homer off Mets reliever Scott Atchison was the Diamondbacks' seventh walk-off win of the season.
Arizona has won three in a row for the first time since July 11-13 and trail the Los Angeles Dodgers by 5 1/2 games for first place in the NL West.
New York plated two runs in the eighth inning off Heath Bell, who had not allowed a run in 11 straight appearances. However, he gave up three consecutive singles to load the bases before Justin Turner and Wilmer Flores each pushed a run across with groundouts.
Turner ended 2-for-4 and drove in three runs for the Mets, who couldn't build off a three-game sweep of the Colorado Rockies and lost for the sixth time in their last eight road games after Goldschmidt blasted Atchison's offering.
"I just left a cutter up," Atchison said. "He's a good hitter ... and he made me pay for a bad pitch."
Brandon McCarthy makes his second start for the Diamondbacks since a stint on the disabled list and looks to build up his stamina.
In his first outing since May 30 due to a shoulder injury, the right-handed McCarthy took a 4-0 loss to Boston on Sunday. He pitched four scoreless frames before yielding two runs in the fifth frame while recording just one out and logging 97 pitches in total.
"Towards the end, I just felt my lack of game shape," said McCarthy. "I just wasn't able to execute as much as I'd like and the ball kind of started getting up a little bit. Against a team like that, you're going to pay for it a little bit."
The 30-year-old is 2-5 with a 4.94 earned run average in 12 starts this season, his first with Arizona, and has never before faced the Mets.
Taking the mound for the Mets will be 23-year-old Zack Wheeler, who lost for the first time in four decisions on Sunday. He dropped a 6-2 decision to Kansas City, allowing four runs -- three earned -- on five hits and a career high-tying five walks over five innings of work.
Wheeler fell to 4-2 with a 3.91 ERA in nine starts this year following the loss, but is 3-0 with a 2.37 ERA in five road assignments. The righty faces Arizona for the first time.
The Mets and D'backs split a four-game set in New York from July 1-4.