PHILADELPHIA — Every step took something out of the Mets. Every day brought a new injury, a new hurdle, a new set of parameters to overcome.

But for six weeks, the Mets stood in defiance of fear and fate. They trained their focus on extricating themselves from the fringes of the race. Because of it, a franchise so often pockmarked by promise unfulfilled could rejoice in an improbable return to the postseason.

It became official in a 5-3 victory over the Phillies on Saturday, when the Mets clinched one the National League’s two wild cards.

Michael Conforto entered into a slide in leftfield to track down Aaron Altherr’s broken bat bloop. Jeurys Familia raised his right hand, trusting it toward the sky. Catcher Travis d’Arnaud clutched him. And in an instant, they found themselves awash in a sea of blue, their teammates mobbing them in front of the mound.

For just the second time in franchise history, the Mets have backed up an appearance in the postseason with another, even though attrition has left this team as only a shadow of the crew that won the pennant a season ago. They will host either the Giants or the Cardinals, the two rivals they ultimately outlasted in a dogfight that frayed their roster and tested their resolve.

“I’m very proud of what these guys have accomplished and with all the stuff we’ve had to endure,” manager Terry Collins said, before the Mets made it official.

Little went according to plan for the Mets. By season’s end, Matt Harvey, Jacob deGrom and Steven Matz had been lost to season-ending surgery, leaving three-fifths of the starting rotation in tatters.

At one point, half of the Mets’ opening day lineup had landed on the disabled list, and their hopes for October had flickered. Yet, they clinched on the backs of players who wouldn’t have been uniform had anything gone according to plan. At the end, it seemed fitting.

Jose Reyes, given a second chance only because David Wright went down, knocked in a run. Rookie T.J. Rivera, undrafted and overlooked, added another.

James Loney bashed a two-run homer to put the Mets ahead for good, extending his arms skyward and then dropping his bat like a microphone as the ball cleared the rightfield fence.

Later, Asdrubal Cabrera, with a banged-up knee that should have kept him on the disabled list, tacked on an insurance run with a flare to right.

Colon, expected by now to be in the bullpen, picked up the victory. And if the Mets advance to the NLDS, the 43-year-old will front a rotation now occupied by rookies Robert Gsellman and Seth Lugo.

Familia slammed the door in the ninth with his 51st save. With that, warts and bumps and bruises and all, the Mets began their wild celebration.

The Mets had reached the point in the season when their own will would not be enough. They would need the breaks of a soft schedule. They would need rivals to fade. But since finding themselves in the wilderness on Aug. 19, the Mets have trudged along uphill, losing more players along the way.

On Saturday, after the strain of powering through, their path suddenly opened wide.

To clinch, the Mets needed just one win or a Cardinals loss. The Phillies sent to the mound righthander Phil Klein, a 27-year-old June waiver claim who hadn’t started since Sept. 4 at Triple-A Lehigh Valley. He would be asked to soak as many innings as he could before turning things over to his colleagues in the Phillies bullpen, the same crew that the Mets punished last weekend at Citi Field.

Meanwhile, as the Cardinals played in St. Louis, Jung-Ho Kang bashed a three-run homer to give the Pirates a 3-0 lead. The score was displayed on the out-of-town scoreboard in rightfield, just behind Jay Bruce’s left shoulder.

Klein lasted four innings, holding the Mets to one run on Rivera’s RBI single before passing the baton to Frank Herrmann. He was promptly greeted with a leadoff single by Travis d’Arnaud, who moved to second on Colon’s sacrifice bunt, before scoring two batters later on Jose Reyes’ RBI single to make it 2-0.

Colon departed after five innings, the only damage coming on Ryan Howard’s two-run shot in his final series in a Phillies uniform.

Colon looked distracted — along with everyone else on Monday — when he was chased against the Marlins in their first game since Jose Fernandez perished in a boating accident. Typically unshakable, Colon lasted just 2 1/3 innings, allowing seven runs on eight hits.

“We’re going to write that one off,” Collins said, after Colon held the Phillies to two runs over five innings, pulling him after just 61 pitches.

Loney pushed the Mets back in front 4-2 in the sixth, when his two-run shot off David Hernandez sailed over the fence in rightfield. Loney tossed the bat away with panache, then smiled as he rounded the bases, the Mets dugout cheering every step.

But from there, each passing inning brought forth the possibility of madness. In St. Louis, the Cardinals roared back to tie the game, 3-3. In Philadelphia, Darin Ruf blasted a pinch-hit homer in the seventh inning off Fernando Salas to cut the deficit to one run.

The developments unfolded mere minutes apart.

But if the Mets have proved anything over the last six weeks, it’s that they are not easily rattled. And as the Cardinals pulled ahead in their game, the Mets put theirs into the history book.

The Mets improved to 27-12 since Aug. 20, when they began their climb from 60-62, 5 1/2 games back of a wild card spot, behind four other clubs.

Cabrera, who had just returned from the disabled list when the Mets hit their nadir, recalls believing that good things were still possible.

“We always keep our heads up, we always try to fight every game no matter what,” he said. “We had ups and downs like most other teams.”

And at the time, veteran catcher Rene Rivera noted the timing. Yes, the Mets had played their worst baseball of the season. But their downturn came in the middle of August, not the middle of September.

Time afforded opportunity fro those with the discipline to plod along, without regard for the chaos around them. The Mets passed that trying test, and rewarded themselves at the end with the sweet sting of Champagne.

“That’s the biggest thing in baseball,” said Jay Bruce said. “There’s so many games that you just have to play.”