PHILADELPHIA — The Cubs had already lost. No matter what happens the rest of the way, that will always be a part of the daily equation the next 29 days. The Cubs had gotten themselves good and shut out at Wrigley Field by the Brewers, so that meant someone on the field at Citizens Bank Park was going to pick up the most valuable of all late-summer real estate:

A full game in the standings.

On the last day of August, with the top of September looming, this is all that matters. This is the only arithmetic that counts. The Mets started the day five games out of the last wild card; they could get to four with a win. The Cubs’ magic number to eliminate the Mets was 24; win and that number would stay right where it was.

All they had to do was win.

And then, sonofgun, the Mets won.

They won 6-3, and naturally they had a few nervous moments along the way. There was the bottom of the sixth inning, a run already in and the bases loaded, nobody out. Then Todd Frazier — a hit and an RBI already, two more hits and another RBI to come — made one of the great defensive plays you’ll ever see, leaping and stretching and snaring a César Hernández line drive in the webbing of his glove.

“I’ve never seen him jump that high,” Mickey Callaway said later, laughing. “I’m not sure we ever will again.”

Frazier: “You just hope you can jump high enough and your arm can reach far enough. I could dunk back in high school. Not any more.”

That ball gets by Frazier, it’s 5-4 with the tying run on third. It didn’t get by Frazier. Luis Avilan walked one in but kept it at 5-3, Justin Wilson and Seth Lugo were brilliant at the back end of the bullpen. Two months ago, the first time the Mets season felt like it was spinning around the drain, it all happened in this very place, where on four straight days and nights the bullpen forged a reputation as being something only an arsonist could love.

Last two days, with the season hanging by a thread, it has been virtually perfect.

“We’ve had our troubles in the bullpen,” Mets catcher Wilson Ramos said, “but they are pitching awfully well right now.”

And then there is Ramos, the catcher who has been simply brilliant for a month. There were four more hits for Ramos on Saturday, and the hitting streak sits at 24, and the batting average is all the way up to .299. When nobody else could buy a hit last week, Ramos kept grinding them out, 43 in all for the month of August.

Now others have joined the party: Frazier (eight RBIs so far this series). Michael Conforto (two hits, and the RBI double that put them up for good). Joe Panik, who struck out with the bases loaded early and then plated a pair with a rocket-shot double late.

“I feel awfully good at the plate,” Ramos said, shrugging his shoulders.

“He’s hard to pitch to right now,” Callaway said. “Eventually, you’ll make a mistake and he’s going to take you to right field.”

The odds are still so steep against the Mets, a reality they crafted for themselves across the latter two-thirds of that ill-fated nine-game homestand. There are just 27 games to play. There are still the Phillies, Brewers and Diamondbacks abreast or ahead of them, in addition to the Cubs. It will probably take 20-7 in September to have a real shot.

They were 14-8 in July, and 17-11 in August, and it felt like they were raging hot both months and they’ll need to be even better than that across the season’s final 29 days to run through the tape. It isn’t ideal. But they have reached the top of September and they still have a pulse. Watching the Cubs’ scores matters. Scoreboard watching is a contact sport.

“We have an opportunity,” Callaway said. “An opportunity to win the next game. A chance to give ourselves more opportunities day in and day out.”

Twenty out of 27 sounds daunting, and ominous, so for the Mets it’s best to look at it another way: Go 1-0 today. Go 1-0 tomorrow. Keep the magic number where it is as many days as you can. Shrink the margin in the standing whenever you can. Worry about today. Don’t worry about Sept. 29.

“Take your best shot,” Callaway said.

Today. Tomorrow. Every day for 29 days. Welcome to the top of September. Welcome to the top of the pennant race.

Purchase event tickets to The Amazin’ 1969 New York Mets: A World Championship for the Ages presented by The Paley Center for Media and New York Post. Enter promo code: NYPOST to unlock tickets only available for Post readers.