Washington gained a split by winning the nightcap 4-2 when Wilson Ramos' ninth-inning grounder bounced off a leg of third baseman Chris Coghlan for a game-ending error that allowed pinch-runner Eury Perez to score. The Nationals trail NL wild-card co-leaders Cincinnati and Pittsburgh by five games with six to play.
The Nationals, who honored Johnson with a 15-minute pregame celebration, dropped 5 games behind Cincinnati for the final NL wild card and have just seven games remaining.
"Like I said before, I'm not very good at math, but I'm good enough to figure out that losing makes it tougher," Washington's Ryan Zimmerman said. "But we've just got to keep playing and see what happens."
Miami had been 0-8 at National Park this season and starter Tom Koehler (4-10) had been 0-4 in eight starts since Aug. 1. Koehler allowed two runs and three hits in six innings, and Steve Cishek pitched a perfect ninth for his 32nd save in 34 chances, completing a four-hitter and a scoreless day for the Marlins' bullpen.
"You can't score six, seven runs every game," Zimmerman said "[Koehler] pitched well and they've got some good arms in the back of their bullpen."
Cishek has converted 27 consecutive save chances, tied for the longest streak in club history.
"You know it's crazy. Out there I had a little more adrenaline pumping. It felt like a playoff atmosphere," Cishek said. "The fans are really into it and those guys are digging in there and every at-bat was huge for them. It felt good to come out and win a game like that."
Dan Haren (9-14) lost to Miami for the third time this year, giving up three runs and eight hits in six innings.
Stanton's 24th homer, a two-run drive after Yelich doubled, put the Marlins ahead in the first.
"I know there's a base open but it's the first inning," Haren said. "I guess in hindsight I could have just walked him. I wasn't trying to just challenge him, I was trying to get a good pitch down and away it just got a little too much plate."
Yelich added a solo shot in the third.
Koehler, who shut out the Mets for eight innings while earning a no-decision in his last start, limited Washington to two singles over the first five innings.
Zimmerman homered in the sixth, his 26th of the season and 11th of September.
"I thought Koehler did a nice job getting through the sixth inning and gave up the one big hit, but did exactly what we needed him to do," Marlins manager Mike Redmond said.
Washington grounded into three double plays.
"We hit a few balls on the button, but right at somebody," Johnson said.
Donovan Solano drove in Miami's final run with a sacrifice fly in the seventh.
Todd Jones saved 27 straight for the Marlins in 2005.. The ceremony honoring Johnson included a pair of video tributes and the presentation of an engraved Tiffany crystal keepsake. ... Juan Pierre got his 2,216th hit, moving past Joe DiMaggio for sole possession of 175th place. ... Stanton has hit safely in 23 of 29 games at Nationals Park with 13 home runs.