PHOENIX -- The Arizona Diamondbacks had chances to win in the ninth inning, again in the 10th, and the next three innings after that.
After all those chances and more than 4 1/2 hours of baseball, David Peralta finally ended it with his first walk-off home run.
Peralta hit his second solo homer off the game off the top of the wall in the 14th inning and the Arizona Diamondbacks rallied from a two-run deficit in the ninth to beat the Philadelphia Phillies 3-2 on Monday night.
"I always wondered what it felt like to hit a walk-off homer," Peralta said. "It's something you can't even describe."
Phillies starter Jake Arrieta allowed three hits in eight scoreless innings, leaving with a 2-0 lead.
His chance at a fifth straight win came undone in the ninth.
Peralta hit a one-out solo homer off Seranthony Dominguez, and Steven Souza Jr. followed Eduardo Escobar's double with a tying single. Luis Garcia replaced Dominguez and walked two to load the bases, but got pinch hitter A.J. Pollock to ground out.
The Diamondbacks kept putting runners in scoring position, but failed getting that crucial hit until Peralta hit the first pitch he saw from Austin Davis (1-2) off the wall and out in left-center. Peralta was mobbed at the plate after ending the Phillies' five-game winning streak with one swing.
"This is the type of baseball we were used to playing last year, done it in spurts this year and couldn't have come at a better time," Diamondbacks manager Torey Lovullo said.
Arrieta underwent a massive turnaround in July, going 4-0 with a 2.80 ERA in six starts after going 0-4 with a 6.66 ERA in June.
The right-hander is second in the NL at inducing groundball double plays with 19 and got another in the second inning to strand Escobar after a leadoff double.
Arrieta was lifted after 110 pitches and seemingly in great position, only to watch it go up in smoke with the ninth-inning blowup.
"He pitched great and we definitely strive to win baseball game like that for a starting pitcher who performs like Jake did," Phillies manager Gabe Kapler said.
Godley allowed two runs on five hits and struck out seven in 7 1/3 innings.
After Dominguez gave up the two runs in the ninth, Kapler did not hesitate to bring him out. The right-hander has 12 saves this season, but has been struggling of late and Kapler didn't want to take a chance the game would end in the ninth.
"This is not his best. I am not blind," Kapler said. "I understand the reality is he is not pitching his best right now, but we are not wavering in our confidence whatsoever. We can't wait to get him back out on the mound because we understand how good he is and the talent will prevail."
In the 13th inning, Lovullo faced a dilemma: Hirano was due up third, but Lovullo wanted him to come back to pitch the 14th to save his bullpen. Lovullo initially told Hirano not to swing, but then relented after the Japanese rookie pleaded.
Hirano had yet to have an at-bat in the majors and was 2 for 21 during his career in Japan, but nearly won the game before grounding out, sending a flare to right that landed just foul with a runner on second base.
"It would have been a monumental moment in Arizona Diamondbacks baseball," Lovullo said. "The fact that he made contact is a miracle, but it speaks volumes about what these guys are trying to do."
Diamondbacks: 3B Jake Lamb is expected to have left shoulder surgery on Aug. 15 to repair a frayed rotator cuff. ... Pollock did not start for the second straight game to rest his fatigued legs.
Diamondbacks RHP Zack Greinke is coming off his first loss in nine starts heading into Tuesday's game against the Phillies after giving up two runs in six innings of a loss to the San Francisco Giants. Phillies RHP Nick Pivetta allowed six runs in 2 2/3 innings in his only career start against Arizona.
More AP baseball: https://apnews.com/tag/MLBbaseball and https://twitter.com/ap-sports
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.