PHOENIX -- For the first time in nearly two months, the New York Mets have won two in a row.
And they did it with style.
"The way we won," Mets manager Mickey Callaway said, "is probably more significant than just getting a back-to-back win."
The Diamondbacks led 3-1 entering the ninth and Boxberger (1-3), with his third blown save in 20 tries, struck out the first two batters.
Jose Reyes reached on a bunt single, which Boxberger said "kind of threw the rhythm off."
Reyes scored on Jose Bautista's pinch-hit double that glanced off right fielder Jon Jay's glove to cut the lead to 3-2. Nimmo, who doubled and scored in the first inning, followed with a two-run shot to right field to put New York ahead 4-3.
"When I came up to bat I was just looking to put the barrel on the ball. He's on second base. A base hit ties it," Nimmo said. "For me, personally, and for this team, maybe we've been trying to do a little too much lately, so there I was just trying to get the barrel on the ball.
"I wasn't trying to hit a home run, but I know now with my swing that if I get on the barrel and the launch angle is right, it will go."
Cabrera's solo shot made it 5-3.
"I have to make a better pitch to Nimmo," Boxberger said. "I pulled a changeup right into his barrel? I have to make a better pitch and then we wouldn't be standing here."
The Mets split the four-game series in Arizona and won consecutive games for the first time since May 20-21.
The Diamondbacks were 4-3 on the homestand with a frustrating conclusion.
"But that is what makes this game great," Arizona manager Torey Lovullo said. "It is heartbreaking. It is rewarding. It is fulfilling and we experience all of those emotions and sometimes all in one game. When it ends like it did today, it is tough."
Jeurys Familia (3-3), just off the disabled list, allowed a run in an inning of relief to get the victory.
Alex Avila reached to start the Arizona ninth when first baseman Dominic Smith dropped second baseman Cabrera's throw for an error but Robert Gsellman retired the next three for his third save in seven tries.
Robert Gsellman pitched the ninth for his third save in seven tries.
Clay Buchholz and three Arizona relievers had shut down the Mets since the opening inning until the big rally.
David Peralta doubled in Arizona's first run in the two-run fourth inning and made a diving grab in left field to rob Zack Wheeler of a hit to end the fifth. Jake Lamb's bloop single in the eighth made it 3-1.
Buchholz went 5 2/3 innings, giving up a run and four hits.
Nimmo led off the game with a double, took third on a ground out and scored on Todd Frazier's sacrifice fly to center.
New York won for only the third time in 15 games.
"It was really great to come back and get a win like that," Callaway said. "That's something we were doing early on, which feels like three years ago."
The announced crowd was a sellout of 47,900, second-largest at Chase Field this season behind 48,703 for the season opener.
Mets left-hander Jason Vargas was ejected from the dugout by home plate umpire Jim Reynolds in the bottom of the fourth inning. Vargas is scheduled to start Tuesday night at Colorado.
Mets: Familia had been sidelined since June 7 with a sore right shoulder. To make room, New York optioned RHP Jacob Rhame to Triple-A Las Vegas.
Diamondbacks: RHP Shelby Miller (Tommy John surgery) made his fourth rehab start on Saturday night. He threw 6 2/3 scoreless innings for Class A Visalia against San Jose. Miller allowed three hits and struck out 10 with no walks. He threw 81 pitches, 56 strikes.
Diamondbacks: Arizona heads to Anaheim for a two-game interleague series with the Angels. RHP Zack Greinke (5-5, 3.87) starts for the Diamondbacks in Monday night's opener.
Astros awaken for 7 in 9th, beat Boston 9-2 to tie ALCS 2-2
— Jose Altuve hit a tying home run in the eighth inning and the Houston offense awakened with seven runs in the ninth on Tuesday night as the Astros came back to beat the Boston Red Sox 9-2, evening the AL Championship Series at two games apiece.
Astros explode in 9th inning for seven-run lead
The Astros take over in the ninth inning, scoring seven runs to stun the Fenway Park crowd.
'It's just hard to imagine a bigger hit': Dave Roberts, Los Angeles Dodgers in awe of Cody Bellinger
Facing a potential 3-0 series deficit in the NLCS, the World Series-champion Dodgers received the boost they needed in the eighth inning Tuesday, when Cody Bellinger's three-run homer tied the score in a Game 3 that Los Angeles would go on to win.
Bellinger, Betts rally Dodgers, cut Braves' NLCS lead to 2-1
— Cody Bellinger keeps erasing a forgettable regular season, with his latest big swing putting the Los Angeles Dodgers right back in the NL Championship Series.
Seager cranks 444-foot homer in 1st vs. Braves
Corey Seager lifts a two-run home run 444 feet to give the Dodgers an early lead vs. the Braves.
Lux's drop fuels Dodgers' nightmare fourth inning
Gavin Lux drops a deep fly ball in center field as Walker Buehler is pulled during a four-run fourth inning for the Braves.