The Marlins have dropped three straight, and they are a season-most five games under .500 (44-49). New York (44-50) is now a half-game behind Miami for third place in the division.
"That was one we need to be able to lock down," Miami manager Mike Redmond said. "We've had some struggles holding down the lead in the seventh, eighth innings. Sometimes the ninth has been tough for us.
"I thought we put together some nice at-bats to score a couple runs to give us a lead and we just gave it right back. Today, they got two big hits off the bench and we weren't able to match the big hits."
Christian Yelich homered for Miami, his eighth of the season. But the Mets delivered the crucial hits late.
In two of their last three games, the Marlins blew late leads. At Arizona on Wednesday, the D-backs overcame a two-run deficit with three runs in the 10th inning off closer Steve Cishek.
"We've had some big wins," Mets manager Terry Collins said. "That might be the biggest win of the year for us -- for a lot of reasons. No. 1, we talked coming into the homestand about having a good homestand."
New York pieced together a two-out rally off Dunn. Travis d'Arnaud doubled before Campbell delivered his decisive single with the count full.
Twice the Marlins held two-run leads in the game. Chris Young pulled the Mets even in the seventh inning with a pinch-hit, two-run homer off Bryan Morris.
Tom Koehler exited after 6 1/3 innings, allowing just two hits, but he walked four, with the fourth being crucial. In the seventh inning, with Miami ahead 4-2, Ruben Tejada drew a one-out walk, putting the Mets in business.
Koehler shouldered the blame for the Tejada walk, putting Morris in position of inheriting a runner.
"Can't happen. Can't happen," Koehler repeated. "You've got to give yourself a chance to get an out there. Obviously, that led to me having to be taken out of the game. It's just something that can't happen.
"I felt good. But in certain situations, no matter how you're doing, you've got to be able to overcome them. You get a quick out in the seventh, and you've got to be able to get the bats back in [the dugout]. That's all I'm thinking about right now."
Morris had not allowed an earned run in 21 1/3 innings since he joined the Marlins in early June. But that string abruptly came to an end when Young belted the righty's first pitch for a two-run homer to left.
"He's been so good," Redmond said. "Like I said, he just made a bad pitch and he hit out."
Although the bullpen has had its issues of late, it has been pretty solid for much of the first half.
"The 'pen's been great all year," Koehler said. "You throw that same pitch nine more times, who knows what happens. It's just one of those days that they happened to beat some pretty good arms. It's going to happen. It's a long season. I just think it's also tough when you've got to come into a situation with runners on and you have to get through an inning late in the ballgame."
The Mets were able to make the big plays and pitches late.
With the game tied in the eighth inning, New York second baseman Daniel Murphy made a leaping two-out grab to snare Adeiny Hechavarria's liner that would have plated at least one run.
"That was a big play," Redmond said. "You talk about winning games on the road, you got to make plays. You got to get big hits from guys. Today they were able to get a couple big pinch-hits and made a big defensive play there that kept us from scoring and possibly changing the outcome of that game."
Mets right-hander Daisuke Matsuzaka gave up four runs on four hits and he walked four in six innings. The veteran also struck out 10, marking the fourth double-digit strikeout day of his career.
"It's tough because we all know we're a better team than the level we're playing at right now," Koehler said. "We're just, whether it be that big play, that big pitch, that big hit. ... You can see, Adeiny hit the ball on the button, and Murphy makes an outstanding play. For us, we've got to have the tide flip a little bit, and us be the ones jumping through the roof."