Finally, a marathon for the Mets that ended in exhilarated exhaustion.

“It was just a fun inning,” Andrew Brown said after his two-run single in the 13th inning gave the Mets a 5-4 victory over the Diamondbacks at Citi Field. “That’s the way it’s supposed to be written up, I guess, right?”

After losing to the Marlins in 15 and 20 innings, respectively, earlier this season, this 5-hour, 13-minute tussle was more bearable for the Mets.

Cody Ross’ solo homer in the 13th off David Aardsma put the Diamondbacks ahead before Josh Satin started the winning rally with a double off Josh Collmenter in the bottom of the inning. John Buck was intentionally (and questionably) walked and ace Matt Harvey entered as a pinch-hitter for Aardsma. Manager Terry Collins elected to have Harvey sacrifice bunt the runners to second and third. Then Omar Quintanilla was intentionally walked and Brown won it at 12:24 a.m. with a single to left-center that scored two runs.

The Mets also got a huge performance from their bullpen, with Carlos Torres, Josh Edgin, LaTroy Hawkins, Bobby Parnell and Aardsma allowing one run over seven innings behind Shaun Marcum.

“If you’re going to be out there that long, you might as well win the game,” Collins said. “You want to win the game bad. We were out of pitching, I can tell you that. We were getting low on pitching, so I was glad we won when we did.”

Though Buck walked three times — twice intentionally batting ahead of the pitcher — he finished 0-for-4 with three strikeouts and six runners left on base on a night the Mets stranded 20.

Satin’s RBI single in the ninth against ex-Met J.J. Putz scored Marlon Byrd with the tying run. Byrd doubled with one out — nearly clearing the left-field fence to tie the game — and wasn’t stopping on Satin’s single to left moments later. Ross’ throw home beat Byrd, but catcher Miguel Montero couldn’t hold on.

“Losing a game like this, I don’t want to say [would be] devastating, but it definitely makes it not worth it,” Satin said. “Winning a game like this just makes the 5 1/2 hours or whatever we were out there that much more worth it.”