MIAMI — Wei-Yin Chen of the Marlins was sharp through four innings in his first game since July 20.

Chen allowed a three-run homer to Danny Espinosa in the fifth but Miami was able to score twice in the sixth and went on to beat the Washington Nationals 4-3 on Monday night.

“Obviously, a good one for us being on life support,” Marlins manager Don Mattingly said in reference to the team’s slim playoff chances. “A lot of good things happened. Wei-Yin was really good, the air came out of the balloon quick in the fifth.”

Miami trails San Francisco and St. Louis for the second wild card spot with 12 games left.

Giancarlo Stanton hit his 26th home run and Christian Yelich, Ichiro Suzuki and Derek Dietrich also drove in a run for the Marlins.

Brian Ellington (3-2) picked up the win with an inning of relief and A.J. Ramos pitched the ninth for his 38th save in 41 chances.

The Nationals have lost three straight.

A.J. Cole allowed two runs and four hits in four innings for the Nationals. He struck out three and walked two.

“I didn’t have my best stuff, but I fought to keep my team in the game and I went out there and still tried to throw my stuff where I wanted to and battle through it,” Cole said.

Mat Latos (7-3) took the loss, allowing two runs in 1 1/3 innings.

Chen made his first start in two months due to an elbow strain, and allowed three runs and four hits, ending his night after 4 1/3 innings. Chen threw 44 of 66 pitches for strikes.

“I haven’t been pitching in a game for a really long time and (my stamina) could have been a factor,” Chen said through a translator.

Washington trailed by a run to begin the ninth when Wilson Ramos led off with a double to left-center field. Michael Taylor pinch-ran for Ramos and was thrown out at third on a groundball to shortstop Miguel Rojas.

“I can’t speak for what a guy was thinking, but that was a mistake,” Nationals manager Dusty Baker said.

Pinch-hitters Bryce Harper and Daniel Murphy flied out to end the game leaving a runner stranded at first.

The Nationals trailed by a run in the seventh and had two on and no outs. Fernando Rodney was able to get out of the jam without allowing a run to score.

The Marlins took an early 2-0 lead on Stanton’s solo home run and an RBI double by Yelich.

Espinosa’s homer put the Nationals up 3-2.

“I was trying to get something out over the plate so I could get it to the outfield and ensure one run — a fly ball or something like that,” Espinosa said. “He threw me a couple good changeups and I just tried to settle down and wait for a pitch that I could get at least one run in.”

Miami responded with two runs in the sixth to take a 4-3 lead behind an RBI double by pinch-hitter Dietrich and a failed fielder’s choice by Suzuki that allowed Justin Bour to score as second baseman Wilmer Difo’s throw was wide to home plate.

“These guys could have quit after the three-run homer but we put up good at-bats and kept going hard and we prevailed,” Marlins second baseman Dee Gordon said.

BOUR’S BUNT

Bour dropped a successful bunt to the open left side of the infield in the pivotal sixth inning with the Nationals in a shift for the left-handed hitter and he later scored the eventual game-winning run.

It was Bour’s first bunt for a hit this season and he does not have a sacrifice bunt in 247 career games.

“I saw a situation and at this point every game is huge for us,” Bour said. “Whatever it takes to get the job done and I had an opportunity to bunt.”

TRAINER’S ROOM

Nationals: RHP Stephen Strasburg (elbow) played catch on Monday for the first time since leaving his Sept. 7 start early. … C Jose Lobaton (ankle) has not played since Sept. 13 when he was a defensive replacement.

Marlins: LHP Adam Conley (finger) is going to throw a simulated game on Wednesday and could re-join the team in some capacity before the end of the season. “He’s feeling really good,” Mattingly said. “He came into my office and told me he feels totally healthy.”

UP NEXT

Nationals: RHP Tanner Roark (15-8, 2.75) will start the second game of the series with the Marlins. Roark is 2-1 with a 1.08 ERA over his last four starts.

Marlins: RHP Jose Fernandez (15-8, 2.99) enters Tuesday’s start with 174 1/3 innings on the season with the goal of keeping him in the 180-inning range. “Obviously we don’t want him to throw innings that we don’t need him to throw, but I think we’re still paying close attention to him,” Mattingly said. “He’s got his mind set on three more starts, but we have to be mindful of how it goes with what we do with him.”