Even at the end of an exhausting series, the Arizona Diamondbacks are a determined bunch in extra innings.

Cliff Pennington hit an RBI single with two outs in the 15th and the Diamondbacks, boosted early by Gerardo Parra's bunt double, finally outlasted the New York Mets 5-4 in a back-and-forth classic Thursday to split a draining four-game set at Citi Field.

Arizona scored in the final three innings but couldn't close out the feisty Mets until Brad Ziegler retired Kirk Nieuwenhuis on an easy grounder with runners at second and third to finish a game that lasted 5 hours, 46 minutes.

"It's a grind, but if we want to win a world championship, we're going to have to endure a lot worse than that," Diamondbacks manager Kirk Gibson said.

Anthony Recker and Nieuwenhuis hit tying homers in consecutive extra innings for New York, making its final home appearance before hosting the All-Star game July 16.

Meanwhile, the NL West-leading Diamondbacks improved to 10-3 in extra innings, the most such wins in the majors.

"There's no question this team will fight to the end of the game," Ziegler said. "It's just two really competitive teams going out and putting on a show on a holiday."

In a span of four days, the clubs played a 13-inning game, a 15-inning marathon and two others delayed by rain for a total of 3 1/2 hours. The 16 hours, 40 minutes worth of baseball marked the second-longest four-game series in the majors since 1987, according to STATS. The Dodgers and Astros played 11 more minutes inside the Houston Astrodome back in 1989.

So it was only fitting that the finale Thursday went on and on throughout a humid afternoon as kids who lined up beyond the outfield wall in the eighth inning waited patiently to run the bases after the final out.

"It felt like a marathon tennis match, to be honest with you," Nieuwenhuis said. "It's tough not to come up on top there at the end, but it's a 162-game season and we've got to bring it tomorrow."

Cody Ross drew a bases-loaded walk from New York reliever David Aardsma in the 13th, but the Diamondbacks squandered a great chance to add on. And of course, with two outs in the bottom half, Recker homered off Heath Bell to tie it again.

Arizona pushed across another run in the 14th on Martin Prado's bloop RBI single off Brandon Lyon with two outs.

Moments later, Nieuwenhuis sent a one-out liner barely over the left-center fence off Chaz Roe (1-0), who made his major league debut in the series opener Monday.

Recker and Nieuwenhuis were both batting .167 when they connected. The Mets said the last time a team hit two tying homers in extra innings was 1998, when Ray Lankford and Eli Marrero did it for the Cardinals.

"At first, you get disappointed. You've got the lead, they hit the home run. And it's disappointing when you have to reload and understand what's ahead of you," Gibson said. "Then, they hit the second one and you've just got to tell yourself, `You can take it.' You learn a lot about yourself in series like this and days like this."

Scott Rice (3-5) retired his first two batters in the 15th before Parra singled. Wil Nieves followed with a single for his fourth hit and Pennington lined a single to left to make it 5-4.

Pennington is 8 for 11 with three RBIs in extra innings this season.

Ziegler walked two in the bottom half but hung on for his first save since 2011 with Oakland.

And at last, it was over.

"This is one of the good signs for this club: We're really good in close games," Gibson said. "A good character check today. They all stepped up."

The Mets are no strangers to long games themselves- especially on July 4. They lost a 20-inning marathon at home to Miami last month, won a 20-inning game in St. Louis three years ago and came out on top in an Independence Day thriller at Atlanta in 1985.

That rain-delayed 16-13 victory is best remembered for Braves pitcher Rick Camp's tying homer with two outs in the 18th and the postgame fireworks that went off around 4 a.m.

By pulling out this test of endurance, the Diamondbacks finished 3-7 on a long road trip against three NL East teams.

"It was exhausting, especially when we got the lead twice and we kept losing it," said Nieves, who had a teddy bear in his bag to bring home to his daughter.