MIAMI — Otto Lopez crushed a two-run homer to left field — his 10th of the season — to cap a furious six-run ninth inning as the Miami Marlins stunned the Washington Nationals and pulled within three games of the San Diego Padres (72-65) in the battle for the final National League Wild Card.

The rally began when Esteury Ruiz reached on a bunt single, followed by two walks and a hit batter that loaded the bases. Joe Mack hit a tying sacrifice fly, and the go-ahead run scored when center fielder Andrew Pinckney’s throw sailed into the Marlins’ dugout. Jakob Marsee then swiped home on a double steal before Lopez delivered the exclamation point.

“We never stopped competing until the end and we created a situation,” Lopez said. “We just feel like, no matter what, we’ve got to finish the game.”

The win moved the Marlins to 69-68 on the season. Miami also swiped three bases in the decisive ninth, pushing its season total to 146 stolen bases — just one behind Washington’s MLB-leading 147. Marsee’s steal of home was his 21st of the year, while Ruiz leads the club with 30 and Lopez sits second with 29.

“I think even the last couple days, late in the game, we’ve battled at the end,” said Marsee, who was hit by a pitch from Tom Cosgrove to force across the first run after Max Kranick loaded the bases. “We just haven’t gotten going early in games this series. No matter what, this team always battles and finds a way to make it close at the end or take the lead.”

The comeback nearly mirrored Saturday’s effort, when Miami rallied for four runs to tie in the seventh before falling in extras. Lopez’s round-tripper was only the fourth hit of the game, but the Marlins drew at least five walks in all three contests of the wraparound series against Washington.

“We don’t rely on everything on the slugging,” Lopez said. “We try to slug, but when it’s not happening, we just create situations.”

Janson Junk allowed one run over 4 2/3 innings to close August with a 2.59 ERA for the month. Dax Fulton earned his first MLB victory after allowing one run in the eighth, limiting damage when he induced Daylen Lile into a sacrifice fly with runners on the corners. Calvin Faucher got four outs, and Victor Vodnik escaped a bases-loaded jam in the seventh by getting Nasim Nuñez — who had doubled in the lone run off Junk — to chop into a 4-2-3 double play. Michael Peterson worked the ninth.

“A lot can be said about the ninth inning, it was its own part of this game,” manager Clayton McCullough said. “Those guys gave us the chance to have a rally, and we had in this game, really one good inning [at the plate].”

The Marlins continue their pursuit of the final Wild Card spot as September baseball begins with Miami facing a three-game deficit against San Diego.