PHILADELPHIA — The bats came back just in time. But the bullpen nightmares did, too.

So the Mets left Citizens Bank Park beaten, battered and beaten again from a road trip that finally came to a close in brutal, yet fitting, fashion.

After Todd Frazier’s two-run homer in the top of the ninth pulled the Mets from the depths of despair with a three-run rally, the Phillies came back in the bottom half to stomp on their throats once more with a five-run rally of their own off Edwin Diaz to win, 6-3, and complete a four-game sweep.

Jean Segura clinched the Phillies’ second straight walk-off with a three-run homer to left field, four batters after Maikel Franco had tied it with a two-run bomb. The crushing blows dealt the Mets (37-45) their fifth straight loss, but this was one of their worst of the season and it capped a 3-8 road trip.

“It’s tough to swallow,” manager Mickey Callaway said. “This one stings the worst because it just happened. This is a game we all felt we really needed to win. Again, we put ourselves in a position to do that and we didn’t get it done.”

Diaz’s blown save — his fourth in his last eight chances — was the Mets’ league-leading 20th of the season, their third in the series and fourth in the past five games. Diaz issued a leadoff walk to Cesar Hernandez before Franco took him deep to left-center field. Diaz retired the next batter, but then walked Sean Rodriguez and allowed a single to Scott Kingery before Segura’s blast.

The Phillies (43-38) entered the series having lost seven straight, and while some in their clubhouse may credit a bamboo plant for their sudden turnaround, the Mets’ bullpen gave them quite a hand.

“We were in a lot of the games, but they just didn’t go our way,” Diaz said.

The Mets were left licking their wounds as they headed home, where a celebration for the 50th anniversary of the 1969 World Series championship team awaits. They are eight games under .500 and 11 games back of first place in the NL East — both season-highs.

“We’re trying, we just can’t find ways to finish games,” Frazier said. “Hopefully that starts soon because we’re in a slide here and we’re not stopping.”

Frazier had briefly looked like the hero in the top of the ninth. After entering the inning with just one hit, from Zack Wheeler, the Mets recorded four against Phillies closer Hector Neris. Down to their last two outs, Frazier’s home run gave them a 2-1 lead. Singles from Dominic Smith and Wilson Ramos and a groundout from Amed Rosario pushed it to 3-1. It only made the bottom of the inning all the more deflating.

Wheeler was strong again, with his arm and bat. He broke up Aaron Nola’s no-hitter in the sixth, but was on the hook after he gave up a solo homer to Bryce Harper in the bottom of the inning.

During the Mets’ 11-game road trip through Atlanta, Chicago and Philadelphia, their bullpen allowed 31 runs in 31 ²/₃ innings. Their prized closer, Diaz, blew one game. Their best reliever, Seth Lugo, blew two.

But the unit’s struggles weren’t isolated to the trip, nor were the Mets’ as a team. Instead, the 11-game stretch just served as one more nail in the coffin.

“It wasn’t just these four [games], it was about seven on this road trip that we could have easily won,” Callaway said. “It’s not just this road trip. That leads back into our last home stand and even the road trip before that. We’ve been way too close to have this many losses.”