PHOENIX -- The Arizona Diamondbacks rallied from an early four-run deficit before nearly blew a four-run lead late. Their manager and a reserve infielder were ejected after the same player got hit by a pitch twice in three innings.
The Philadelphia Phillies saw catcher J.T. Realmuto -- 0-for-13 in his previous four games -- complete the cycle in the ninth inning, then thought they had a go-ahead homer on a ball that curled into their bullpen.
A wild night in the desert ended with the Diamondbacks' sixth straight win.
Evan Longoria hit a three-run homer and the Diamondbacks withstood Realmuto hitting for the cycle to beat the Phillies 9-8 on Monday night.
"This team is unfazed, we're just going to keep playing," said Diamondbacks manager Torey Lovullo, who was ejected in the third inning. "Like they're a bunch of black labs running around chasing frisbees on the beach."
This was no day at the beach. More like an exhausting night in the desert with 25 combined hits -- 10 for extra bases -- and numerous twists and turns.
Realmuto got it started with a solo homer in the first inning and a two-run triple in the third to put the Phillies up 5-1. He hit a double in the ninth inning to complete Philadelphia's ninth cycle in franchise history and first since David Bell in 2004 and scored on Bryson Stott's single to cut Arizona's lead to 9-8.
Philadelphia's Kody Clemens pinch-hit and thought he had hit a two-run homer off Miguel Castro, cheering as he circled the bases after the ball curled into the Phillies' bullpen. The umpires ruled it a foul ball, confirmed it upon review and Castro struck out Clemens on the next pitch to end the game for his seventh save.
Realmuto is the first catcher since George Kottaras in 2011 to hit for the cycle and 17th in major league history.
Realmuto put the Phillies up 5-1 with his triple in the third inning, but the action picked up after the teams nearly came to blows in the bottom half.
Philadelphia starter Matt Strahm hit Arizona's Corbin Carroll with a pitch in the first inning, then plunked him again in the third inning, firing up Lovullo and the Diamondbacks.
"Zero intent to hit him on both," Strahm said. "I didn't think I missed that far inside for that type of reaction."
Knowing he wasn't supposed to leave the dugout, Lovullo did anyway to stick up for his player, believing Strahm had pitched too far inside for comfort.
While he was talking to plate umpire Vic Carapazza. Realmuto started talking to the Arizona manager, triggering an argument that sent players rushing out of both dugouts and bullpens.
Carapazza ejected Lovullo, then kicked out Diamondbacks reserve third baseman Josh Rojas after Strahm got into a yelling match with someone in Arizona's dugout.
"I have nothing but respect for J.T. Realmuto," Lovullo said. "This was me protecting our player and him protecting his pitcher, and there was just a disagreement. I don't want to talk about what was said between J.T. I knew going out there that I had no right to go out there."
The Diamondbacks rallied around their manager.
Pavin Smith had a run-scoring single in the third inning and Emmanuel Rivera added one in the fourth. Allowed to swing his third at-bat, Carroll lined a run-scoring triple into the right field corner to tie the game at 5-all. He reached base four times and scored twice after being named NL player of the week.
Rivera's sacrifice fly off Dylan Covey (1-2) in the sixth inning gave Arizona the lead and Longoria followed with a towering three-run shot over the wall in left-center.
"It fired us up, but our foot is always on the gas pedal as a team," said Arizona outfielder Jake McCarthy, who went 3 for 4. "We obviously back our guys and wanted to go out and finish strong."
Bryce Harper lined a run-scoring single off Drey Jameson (3-1) and Alec Bohm followed with another to pull Philadelphia within 9-7 in the seventh inning. After some tense moments, the Diamondbacks finally closed it out.
"I'm exhausted right now," Lovullo said.
ESPN Stats & Information and The Associated Press contributed to this report.