NEW YORK -- Blake Parker pounded his fist into his glove Sunday afternoon, looked up to the sky, and took a deep breath.

The Phillies flirted with disaster in the seventh inning of a 10-7 win, but Parker escaped. They were three more outs closer to a needed victory in a stretch of games that all feel like must-wins as the Phillies cling to slim playoff hopes. It was finally safe to exhale.

The Phillies scored their most runs in nearly two weeks, but nothing came easy. They used eight pitchers, received production from almost every part of their lineup, and picked up ground in the wild-card race. The Cubs and Diamondbacks, the two teams ahead of the Phillies for the National League’s second wild card, both lost on Sunday. The Phillies are two games out of the playoffs with 20 games to play.

Gabe Kapler said this weekend that the Phillies were playing with “a chip on our shoulders.” They understood that most outsiders were beginning to count them out. They didn’t believe it, Kapler said. The manager said they would “keep fighting and clawing for every last inch.” The fight is just getting started.

Parker, signed in July after he was let go by Minnesota, allowed the first three batters in the seventh inning to reach base. A four-run lead was down to three and the heart of the Mets order was due up. The cracks of a late-inning meltdown were beginning to form.

But Parker battled back. Jeff McNeil flew out. Pete Alonso, the National League’s home-run leader, popped up. Michael Conforto struck out looking at a low fastball. The Phillies were another out closer to a win.

“All we can do is fight,” Kapler said. “We’re a little bit tapped. But at the same time, we’re pretty gritty. And I’m proud of that.”

They won two of three games this weekend at Citi Field to begin a stretch of 20-games against teams with a winning record. The Phillies have a tough draw as they begin a six-game homestand on Monday against the Braves and Red Sox. They then travel to Atlanta, Cleveland, and Washington.

If the Phillies reach the playoffs, they’ll have to fight their way in. The Brewers, who are tied with the Phillies behind the Cubs and Diamondbacks, will play 17 of their final 20 games against teams with a losing record. The Phillies will be rooting hard this month for teams like the Marlins, Padres, and Pirates.

“We know we have a long way to go,” Kapler said. “We have a tough schedule. We’re going to have to be especially resilient to make it through this very difficult stretch. But I believe in that club. I believe in the fight in that club.”

Parker’s inning of work was tense, but it would have been even more stressful had Scott Kingery not battled back from a two-strike count to homer in the top of the inning. The Phillies had watched their three-run lead trim an inning earlier to just one. They knew they needed more runs. And then Kingery blasted a two-out, two-run homer to left.

It gave the bullpen some rope and allowed an inning to extend long enough for Bryce Harper to enter as a pinch-hitter and work a bases-loaded walk. The Phillies won the series despite Harper being held out of the lineup on Saturday and Sunday after being hit by a pitch on Friday night. They won Sunday without J.T. Realmuto, who received a rare day off.

They won thanks to Adam Haseley, who homered in the fourth inning, and Corey Dickerson, who had a two-run single in the fifth. They won because of Phil Gosselin, who spent most of the summer in triple-A, hit an RBI single in the sixth and then scored when Maikel Franco, who was in triple-A eight days earlier, followed with a two-run homer. They were boosted by Sean Rodriguez, who ended the sixth with a sliding catch in right field.

“I think this is a great way to develop some solid momentum going into the homestand,” said Vince Velasquez, who allowed four runs in 41/3 innings. “I know we have Atlanta coming up and it would be awesome if we could win that series. This creates some series momentum.”

They pieced together the late innings with relief work from Parker, Mike Morin, and Nick Vincent. The three pitchers were added in July after being cast off elsewhere. The Phillies now need them to keep their playoff dreams alive.

“We definitely ask a lot out of our bullpen, but we’re trying to win every single baseball game,” Kapler said. “We have to to try to win the inning before we can decide what comes tomorrow.”

They then handed the game to Hector Neris, who allowed two hits in the ninth inning and brought the tying run to the plate before finishing off the Mets. Finally, it was safe to exhale. But the fight is just getting started.

“At the end of the game, when Hector was out there, I looked down at our dugout and everyone was up,” Kapler said. “Everyone was locked into the game. It was a long game and it didn’t seem like anyone was exhausted. Guys were at the edge of their seat rooting their team on. In order for us to be successful, we have to continue to fight.”