The Marlins ended a nine-game losing streak and won for just the 14th time in 55 games this season.
Jacob Turner, making his season debut for the Marlins, gave them a much-needed solid pitching performance.
Having been called up from Class AAA New Orleans, Turner (1-0) blanked the Mets on five hits through seven innings with one walk and three strikeouts. It was his third win in 14 career major league starts.
The game was scoreless into the seventh, but Miami struck for four runs on four hits in the inning off Shaun Marcum (0-6).
Derek Dietrich doubled leading off the seventh, moved to third on a single from Marcell Ozuna and scored on a base hit by Ed Lucas.
Miami's most recent victory had come on May 20 against Philadelphia. The Marlins won just six times in the month.
Exploding whale video goes viral on Internet
Jordana Brewster on Paul Walker: 'He was an enormous presence in my life'