ST. LOUIS -- Derek Dietrich summed up the game's pivotal at-bat in one short sentence Sunday.
"I'm glad I got a pitch I could hit," the Miami Marlins' left fielder said.
Pouncing on a low breaking ball from St. Louis Cardinals starter Carlos Martinez that caught the plate's middle, Dietrich laced a three-run triple to cap a four-run fifth inning as Miami rallied to post a 6-4 win at Busch Stadium.
All the runs in the inning were unearned, thanks to a botched double-play ball by second baseman Kolten Wong, but the Marlins were happy just the same to avoid a series and season sweep at St. Louis' hands.
"When you beat this team, you have to earn it," Miami manager Dan Jennings said. "I thought we had a good game up and down our lineup with guys grinding at-bats, and our bullpen really came through for us."
Jennings was calling for the bullpen in the bottom of the third inning when starter David Phelps, a St. Louis native, departed with right elbow discomfort that Jennings said would land him on the disabled list Monday.
Chris Narveson (1-0) worked 2 2/3 innings, allowing the first major league homer of left fielder Stephen Piscotty's career in the fifth. Four other relievers teamed for four innings of one-hit work, with closer A.J. Ramos notching two strikeouts in a clean ninth for his 19th save in 24 tries.
Prior to this win, the Marlins (47-70) had lost all five games this year to the Cardinals and had a six-game losing streak against them, dating back to Aug. 13, 2014.
"This is a good place to play, but you know when you come in here you're going to have to scrap and fight for everything you get," Miami catcher Jeff Mathis said.
It was Mathis' grounder that set the game-changing inning into motion. With shortstop Adeiny Hechavarria on first after a leadoff single, Mathis hit a sharp grounder right at Wong. But it went through his legs and into right-center field.
Narveson followed with a sacrifice bunt that scored Hechavarria. Plate umpire Phil Cuzzi originally called Hechavarria out, but a replay review in New York City reversed the call after 2 minutes and 50 seconds.
Three batters later, Dietrich produced the hit that put the Marlins ahead for good.
"I tried to get out of it in a good way, but sometimes bad things happen," Martinez said through an interpreter. "It's part of the game. Sometimes it's good, and sometimes it's bad."
Martinez (12-5) permitted seven hits and five runs -- just one earned -- in five innings with no walks and five strikeouts.
Right fielder Jason Heyward used two swings to personally erased Miami's 1-0 first-inning lead, achieved on a two-out RBI single by first baseman Justin Bour.
After cracking a game-tying homer in the first, Heyward then belted a two-run shot in the third, his 11th of the year and his first multi-homer game since Aug. 17, 2013, when he played for Atlanta.
On his next pitch, Phelps doubled over in pain and was quickly lifted for Narveson, who started the Marlins on their comeback path.
"Great job by the bullpen to give up just two hits in 6 2/3 innings," Jennings said. "St. Louis is the best team in baseball for a reason, because they play the game the right way. But they made two mistakes today and we jumped on them."
The other miscue also came from Wong, whose error on a potential double-play bouncer by pinch-hitter Casey McGehee in the sixth allowed Miami's last run to score.
The Cardinals (75-42) saw their National League Central lead over Pittsburgh, an 8-1 winner at the New York Mets, shrink to five games.
NOTES: St. Louis LF Stephen Piscotty has the National League's eighth-best average at .338 since being called up from Triple-A Memphis July 21. ... Miami entered Sunday's game with only 57 errors in 117, its fewest number of boots at this stage in franchise history. ... Cardinals SS Jhonny Peralta didn't start Sunday as Pete Kozma got the call instead. Peralta broke out of a 1-of-17 skid Tuesday night and has hit safely in five straight games.