Miami won its third in a row with one of its runs being unearned thanks to one of the three St. Louis errors.
Heath Bell came on in the ninth for the Marlins to protect a 3-1 lead, but gave up a run on a double and infield single, then hit a batter to put runners on first and second with two away.
Bell, however, got Carlos Beltran on a grounder to second to end the game and collect his 19th save.
He preserved the win for Ricky Nolasco (8-6), who gave up nine hits but only one unearned run in six innings.
Jake Westbrook (7-7) suffered the hard-luck loss, allowing two runs -- one earned -- on five hits over 6 2/3.
'SNL': 'Anchorman 2' cast, One Direction sing 'Afternoon Delight' [VIDEO]
Exploding whale video goes viral on Internet