PHILADELPHIA — Time is running out for the Miami Marlins.

A.J. Ramos struggled against the Philadelphia Phillies once again, allowing three hits and a walk in the bottom of the 13th inning as the Marlins lost 4-3 Friday night and fell five games behind the New York Mets for the second NL wild card.

Ramos (1-3) let the first two batters reach base in the 12th, but got out of the jam when he induced a double-play grounder from Andres Blanco.

The right-hander wasn’t as fortunate an inning later when he loaded the bases with one out. Pinch-hitter Jimmy Paredes lined a game-winning single over a five-man infield.

Ramos is 0-4 with a 5.58 ERA in 35 career relief appearances against the Phillies.

“Every (loss) is painful from the standpoint of you know where you’re at, and you have to think about winning absolutely every game,” Marlins manager Don Mattingly said. “Every one is tough, it hurts, you know, and that’s just the way it is this time of year.”

It looked good early for the Marlins (73-74). Tom Koehler cruised through the first five innings on the mound and Dee Gordon gave the Phillies fits with his elite speed. He had three hits, stole two bases, and forced starting pitcher Adam Morgan to be called for obstructing a baserunner on a grounder to first.

That play sparked the Marlins to their first two runs of the game.

After Morgan walked Giancarlo Stanton, Martin Prado doubled home Gordon and, one out later, J.T. Realmuto singled home Stanton for a 2-0 lead.

Prado had three hits, including two doubles.

But the Phillies scored three times in the sixth, including a leadoff homer by Ryan Howard.

Likely playing in his final few games with the Phillies in front of the home crowd, Howard hit his 22nd home run of the season off Koehler.

The Phillies’ bullpen did a fine job in relief of starter Adam Morgan. The relievers allowed just one run in 8 2/3 innings.

That run was a pinch-hit homer by Derek Dietrich off Edubray Ramos with two outs in the eighth that tied the score.

It was Dietrich’s fifth of the season and first career pinch-hit homer.

But while the Marlins were able to consistently get runners on base, they couldn’t get them home.

The teams combined to strand 24 runners and struck out a combined 30 times. Miami left the bases loaded in the 11th and left two runners on base four other times in the game.

“Obviously, our guys really battled tonight, but when you get to the root of it, we left a lot of people out there,” Mattingly said. “We left some guys out there with sacrifice-fly situations or if someone hits a ball in a gap there somewhere, you put a game like this away. We just weren’t able to do it.”

And now they face the daunting task of overcoming a five-game deficit with 15 to play.

“Every loss is major at this point,” Koehler said. “We’re running out of games. But as long as there’s not a little ‘e’ next to us in the standings, we’re going to come out and fight.”

STATS

Prado is hitting .318 against the Phillies this season with eight doubles and eight RBIs. … Koehler made his 30th start, joining Dontrelle Willis and Scott Olsen as the only Marlins pitchers to reach that plateau in three consecutive seasons.

TRAINER’S ROOM

Stanton made his first start since a groin injury on Aug. 9. He had made five pinch-hit appearances since returning last week. With the team limiting his innings, Stanton went 0 for 2 with two walks and grounded into a double play before being replaced in the sixth.

UP NEXT

Marlins RHP Jose Urena (4-6, 4.89 ERA) opposes Phillies RHP Jeremy Hellickson (11-9, 3.76) on Saturday night.