Miami had drawn even in the eighth on Giancarlo Stanton's RBI double. But in the ninth inning, the Nationals were able to prevail in their final home game.
"It was a long day," Miami manager Mike Redmond said. "But we came out and I thought we gave it everything we had. We go home with a split."
The Marlins claimed Game 1, 4-2, but they watched two separate leads slip away in the second game. Justin Ruggiano connected on a solo home run off Stephen Strasburg in the second inning.
Now 57-99, the Marlins have lost their second-most games in a season. The 1999 club dropped 98, and their worst overall season was 54-108 in 1998.
Miami finished 3-8 in its final road trip, and 26-55 overall away from Marlins Park.
Washington won in walk-off fashion after Jayson Werth doubled off Sam Dyson to open the ninth. Eury Perez pinch-ran for Werth after Bryce Harper worked a 2-0 count. Harper was retired on a popup to second, and Ian Desmond was intentionally walked.
A double steal put two runners in scoring position, and the Marlins played the infield in. Ramos slapped a grounder to third that Coghlan misplayed, allowing the winning run to score. The run was ruled unearned and Ramos wasn't credited with an RBI, but the Nationals did claim three of four in the weekend series.
"It's a tough one," Coghlan said. "I just came up on it too quick. I saw him break home, and I came up on an easy ground ball, a ball I catch all the time. I just came up on it."
The Marlins are moving Coghlan around, giving him chances to play outfield and third base, as they make their evaluations for next season.
"We want to see him play there and get as much time and experience out there as he can," Redmond said. "That's just one of those fluke deals."
In looking at the big picture for the Marlins, Sunday marked the final start for Flynn, a 6-foot-7 left-hander who will head into Spring Training competing for a roster spot. In four innings, Flynn allowed two runs on four hits while striking out five. He showed promise, but also a bit of fatigue in the longest season of his professional career.
The Marlins ended up 1-9 at Nationals Park, and 5-14 in the season series. However, their win in the first game dealt a serious blow to the Nats' chances of claiming an NL Wild Card spot. They are five games off the pace with six to go.
Denard Span's two-run single in the sixth inning off Ryan Webb put Washington in front, 4-3. But in the eighth inning, the Marlins tied it on back-to-back doubles by Christian Yelich and Stanton off Tyler Clippard. Yelich hustled his way into a two-base hit on a slow roller past second. With a base open, Clippard went right after Stanton, who ripped a double down the line in left.
The Marlins had led 3-2 in the fourth inning on Adeiny Hechavarria's RBI single off Strasburg, who allowed three runs in six innings.
Flynn was able to preserve the advantage in the fourth inning, but he did so in the most difficult of circumstances. The lefty loaded the bases on two walks and a single to Ramos. With no outs, he wiggled out of the jam, striking out Anthony Rendon and Strasburg.
Flynn fell behind Span, 3-0, before battling back. With the count full, Span bounced a grounder up the middle, and Hechavarria made an acrobatic play, fielding the ball while stepping on second for the forceout to end the inning.
"It's kind of those things where you wish you were never in it, or if you are, getting out of it," Flynn said. "You wish it was in the seventh or eighth inning, instead of the fourth."
The 23-year-old lefty had his night end on a positive note, as he showed the composure to get out of a bases-loaded jam.
The rookie is at 18 innings in the big leagues in September, and 179 total counting his numbers at Double-A Jacksonville and Triple-A New Orleans.
"That's one of those things where you don't feel your best, but who really does this time of year?" Flynn said. "It's one of those things, if I do accomplish what I want to in this game, I'm going to have to make the adjustment to pitch this late into the year.
"Offseason training, to get after it, and come back better and stronger next year. That's one of the things I'll focus on."