New York: The New York Mets defied a welter of injuries to secure a return to the Major League Baseball playoffs on Saturday with a 5-3 victory over the Philadelphia Phillies.

Although the Mets were runners-up in the World Series last season, a return to the playoffs looked unlikely in August, when the injury hit team was languishing 5 1/2 games outside a National League wild card spot.

Twenty-seven wins later, the Mets locked up an NL wild card berth, with James Loney powering them past the Phillies with a two-run homer in the sixth inning.

“This is why you play, to enjoy this kind of a celebration,” manager Terry Collins said.

“If you’re going to play in our town, you better have heart and you better have character to play in New York City. You’re gonna get knocked down, but you better be able to get back up,” he added.

Loney belted a 3-1 pitch over the right field fence to give the Mets a 4-2 lead that their bullpen wouldn’t surrender.

Mets starting pitcher Bartolo Colon went five innings, scattering five hits and striking out six.

Whom the Mets will host in Wednesday’s National League wild card game remained up in the air with the end of the regular season looming on Sunday.

The San Francisco Giants defeated the Los Angeles Dodgers 3-0 on Saturday to retain a one-game lead over the St. Louis Cardinals for the final NL spot.

A Giants win or Cardinals defeat on Sunday would send the Giants to New York.

If the Giants finished the regular season tied with the Cardinals — who beat the Pittsburgh Pirates 4-3 on Saturday — they would meet in a one-game tiebreaker on Monday in St. Louis.

The result in San Francisco locked the Dodgers into the third seed in the National League, meaning they will open the playoffs on Friday at NL East division champions Washington. On the same day, the NL Central winning Chicago Cubs will host the wild card game winner.

The race for the American League wild card berths will go down to Sunday — if not beyond.

The Baltimore Orioles started the day with a one-game lead over Toronto for the first AL wild card spot, but fell to the New York Yankees 7-3 while Toronto defeated the Boston Red Sox 4-3.

The Detroit Tigers’ playoff hopes took a big hit with a 5-3 loss to the lowly Atlanta Braves — although they and the Seattle Mariners maintained a mathematical chance of snagging an AL wild card berth.