In perhaps their most gratifying victory of the season, the Mets battled back Thursday night to beat the Marlins, 7-5. For the first time since 2013, they have a five-game winning streak.

It did not come easily.

In a back-and-forth affair, the Mets rallied from a 3-0 deficit, blew a 5-4 lead, then found themselves tied once more after a lengthy replay gave the Marlins the tying run on a bizarre play at home plate.

But in the seventh, Lucas Duda delivered the go-ahead run, singling off tough lefty Mike Dunn to drive in John Mayberry Jr. Michael Cuddyer followed with a swinging bunt to score Curtis Granderson.

Carlos Torres survived a leadoff double to pitch a scoreless eighth ahead of Jeurys Familia, who nailed down his fourth save. For the first time this season, the Mets (7-3) moved into sole possession of first place in the NL East. They last won five straight from May 26-30, 2013.

Starter Dillon Gee was granted a reprieve only to squander it before he was chased in the sixth. He put the Mets in a 3-0 hole on homers by Giancarlo Stanton and Martin Prado.

But the Mets rallied to tie it in the fifth. Wilmer Flores, who had only one hit on the homestand, crushed a Jarred Cosart fastball over the leftfield fence for a three-run homer.

With one swing, Flores granted Gee a clean slate. It didn't last long.

In the sixth, Gee needed only one more out to preserve the tie. Travis d'Arnaud helped, uncorking a perfect throw to catch Dee Gordon trying to steal second. But with two down and nobody on, the Marlins pushed across the go-ahead run thanks to three walks.

The first two were issued by Gee, who allowed four runs in 52/3 innings. He turned over a bases-loaded mess to Rafael Montero, who walked Marcell Ozuna on the eighth pitch of the at-bat.

Stanton scored to give the Marlins a 4-3 advantage, though it could have been worse.

Earlier in the sixth, leftfielder Cuddyer kept Prado's line single from reaching the wall, which saved a run and perhaps changed the complexion of the inning. Granderson ended the rally by running down J.T. Realmuto's bases-loaded drive to rightfield. Even though Granderson's momentum sent him crashing into the fence, he held on to the ball to limit the Marlins to one run.

It proved crucial in the Mets' half of the sixth, when they pushed ahead 5-4.

Duda doubled and Cuddyer followed with a single to tie it. Two batters later, Eric Campbell lifted the eighth pitch of his at-bat into leftfield. It was a deep enough fly ball to drive in Cuddyer from third and give the Mets their first lead, 5-4.

That's when the Marlins evened it with the help of replay. Ichiro Suzuki came off the bench to line a one-out triple in the seventh. With the infield in, Gordon hit a bouncer right at second baseman Daniel Murphy.

His throw to the plate was wide, but inexplicably, Ichiro stopped in his tracks before realizing his mistake.

D'Arnaud appeared to tag Ichiro, who missed the plate on his first attempt. He reached back to touch it the second time, barely beating d'Arnaud's glove, but Eric Cooper ruled Ichiro out.

But after a 5-minute, 44-second review, umpires overturned the call, giving the Marlins the tying run and once again forcing the Mets to rally.