Masterson, acquired in a trade with Cleveland on July 30, allowed three hits — all singles — and no walks and threw only 91 pitches before departing for a pinch hitter.
After recording only six outs in his previous start, he lowered his ERA to 6.00 in three outings with the Cardinals, and 5.14 overall this year.
The 6-foot-6 right-hander improved to 2-1 with St. Louis and 5-6 overall. He also earned his first career RBI in the sixth with a two-out single.
The Marlins were going for their first three-game sweep of the Cardinals since 1996. A pair of errors by Marlins second baseman Jordany Valdespin led to two unearned runs, and Miami also walked in a run. Nathan Eovaldi (6-7) allowed four runs, two earned, in six innings.
The Cardinals won despite going 2 for 11 with runners in scoring position. They went 4 for 26 in those situations in the series.
Matt Carpenter had three hits and scored twice. He had been 1 for 20 previously against Miami this year.
The Cardinals took the lead in the third on a two-out, two-run single by Matt Adams, who ended an 0-for-9 skid with runners in scoring position.
St. Louis added an unearned run in the fifth when Valdespin made an errant throw trying to complete a potential inning-ending double play. Valdespin mishandled a two-out grounder in the sixth for another error, which led to another run.
Marlins LHP Dan Jennings, who suffered a concussion when he was hit in the head by a line drive on Aug. 7, has been free of symptoms the past two days and played catch before the game. There's no timetable yet for his return.
Marlins newcomer Brad Penny pitches Thursday against Arizona and Chase Anderson. Penny has a 1.93 ERA in 23 games against the Diamondbacks.
Link to box score: St. Louis (63-56) 5 at Miami (59-61) 2
Join the pre-game, in-game and post-game discussion about each contest at The Cardinal Nation message board.