Miami Marlins outfielder Marcell Ozuna doubles to score Christian Yelich during the first inning of a baseball game against the San Diego Padres at Marlins Park in Miami on Aug. 26, 2016. Wilfredo LeeAP

Miami Marlins outfielder Marcell Ozuna doubles to score Christian Yelich during the first inning of a baseball game against the San Diego Padres at Marlins Park in Miami on Aug. 26, 2016. Wilfredo LeeAP

The Marlins capped off a come-from-behind victory over the Padres on Friday night when Chris Johnson delivered a walk-off double in the ninth for a 7-6 victory. It took three hours and 52 minutes, with most of the drama coming at the very end.

Trailing 6-2 in the seventh, the Marlins scored five runs over the final three innings to maintain their position in the wild-card playoff race.

Premium content for only $0.99

Said starting pitcher David Phelps, who was lifted early and was long gone by the time the Marlins mounted their successful comeback: “It was the biggest win of the year for us. The timing of it. What it was looking like …”

It was looking bleak.

The Padres had that 6-2 lead in the seventh when the Marlins began chipping away.

Marcell Ozuna made it 6-3 with his RBI single in the seventh before the Marlins began to turn it on in the eighth. Newly acquired Jeff Francoeur started it off with one of his three hits, and Robert Andino followed with a single of his own.

Two outs later, former Marlin Brad Hand walked J.T. Realmuto, loading the bases for Martin Prado. Brandon Maurer took over for Hand and promptly served up a two-run single to Prado, followed by a game-tying single by Christian Yelich.

In the ninth, Francoeur reached on an infield single. Following a walk to Ichiro Suzuki, Johnson belted a fly ball to deep right-center field that dropped in for the game-winning double.

“It was a great night,” Francoeur said. “Those last three innings, we grinded some great at-bats and made them work. It was a great win.”

It looked for the longest time that Jarred Cosart would pick up his very first win of the season, and it would come at the expense of the team that traded him to San Diego last month.

Though he was far from masterful, Cosart made it through five innings.

But the Marlins didn’t allow that to happen.

The comeback was most pleasing to manager Don Mattingly, who told reporters beforehand Friday that the team’s Achilles’ most of the season had been its failure to score runs late.

“That eighth [inning] was incredible,” Mattingly said. “It’s just one of those wins that you really feel good at the end of the day. These are the kind of games that you want your guys to experience, knowing that every win’s a big one, and this felt good.”

Cosart’s performance could hardly be considered dominating, as he gave up five hits and a couple of walks. But his outing was superior to that of Phelps, who couldn’t get through the fourth.

Phelps, who has pitched well since moving from the bullpen to the rotation, looked out of sorts Friday, coming out during a fourth inning in which he hit a batter, walked one and gave up two hits, the most damaging of which was a bases-loaded double by light-hitting Luis Sardinas.

“It’s a strange game,” Phelps said. “If you watched the whole game, you could see that I wasn’t commanding the baseball to lefties.”

Sardinas, who brought a .175 average for the season into the series opener, would later homer off Mike Dunn to make it 6-2.