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
Bryce, Manny, Corbin and more? What a Yankees spending spree could bring
The Bronx hasn't been home to a World Series champion for almost an entire decade. We offer up five offseason moves that would fix that -- if the Steinbrenners are willing to spend like The Boss.
Which teams should shift gears and become buyers or sellers?
The Diamondbacks have been contenders, but they're among the clubs who might want to shake things up by shopping stars like Paul Goldschmidt.
How the Phillies can be smart spending stupid amounts of money
The Phillies have plenty of payroll space and expectations of contention to deliver on. Here's a plan for which top free agents they should target.
Buster's Buzz: A checkup on the state of baseball
A new TV deal and strong attendance don't jibe with complaints about the changing game. What are the strongest indicators of the sport's health?
Astros acquire Aledmys Diaz in trade with Blue Jays
The Astros, who could lose Marwin Gonzalez to free agency, acquired infielder Aledmys Diaz, who hit a career-high 18 homers last season, in a trade with the Blue Jays.
Dodgers closer Kenley Jansen set for Nov. 26 heart surgery
Dodgers closer Kenley Jansen is expected to be ready for spring training after surgery to correct his irregular heartbeat. The surgery, which had been expected, has been scheduled for Nov. 26, with recovery time anywhere from two weeks to eight weeks.