ANAHEIM, Calif. – You can’t rob ‘em all.

The Phillies rallied from two runs down in the top of the ninth inning to beat the Los Angeles Angels, 5-3, in a wild one Friday night at Anaheim Stadium.

Pinch-hitter Edmundo Sosa belted a two-out grand slam to left-center to rescue the Phils from a 3-1 deficit. Sosa’s first career grand slam came just two batters after Angels’ right fielder Wade Meckler climbed the wall and robbed Bryson Stott of what would have been a go-ahead, three-run homer.

How emotional was that ninth inning?

“I hit all of them,” Stott said. “I was like, ‘What the hell.’ Then I was very mad. And then I was super happy. It was like the biggest roller coaster ever. That was a big swing by Sosa.”

Sosa hit a 1-1 changeup from lefty Sammy Peralta, who had entered the game after triple-digit reliever Ben Joyce hit Alec Bohm with a pitch with one out, walked Justin Crawford, had his bacon saved by Meckler, then walked J.T. Realmuto with two outs to keep the inning alive for the Phillies.

As Sosa rounded the bases, he pounded his chest a little.

Why not?

It isn’t every day you hit a go-ahead grand slam with your team down two runs in the ninth.

“I was just going crazy,” Sosa said.

Sosa’s slam marked the fourth time this season that the Phillies have hit a go-ahead home run with two outs in the ninth inning.

“It’s ceasing to amaze me at this point,” manager Don Mattingly said. “It seems like we’ve done this a few times. We had some great at-bats leading up to Sosa.

“He’s got that kind of pop. You’re not necessarily looking for a home run. You’ll take a ball in the gap or a single. He’s been good. All the guys who come off the bench for us have been good. That’s what I speak about, keeping everybody in the mix where they all have a part of it. It’s good when the pieces fit like that.”

What a week it has been for Sosa. He had a three-run double as the Phillies rallied back from a 4-0 deficit in the bottom of the ninth to beat the St. Louis Cardinals, 6-4, on Sunday. That was the Phils’ ninth win in a row.

The Phils went on the road after that game and lost two of three in Seattle before opening their series against the Angels with one of their most dramatic wins of the season.

Prior to Sosa’s grand slam, the Phils had eight singles on the night. Their only run before Sosa’s grand slam came on a two-out bunt hit by Derek Hill, one of the role players that likes to keep fresh.

Sosa was on the bench when Joyce started melting down in the top of the ninth. He thought there was a chance he’d be called to pinch hit if the Angels went to a lefty.

He was right.

“I think I anticipated that at-bat,” Sosa said. “I started imagining it when Joyce hit Bohmer. I thought we might have a chance to rally and I might have a chance to have a big at-bat. I trusted the opportunity would come and I might have a chance to come through. I stayed focused. I stayed calm and focused. I connected really well.”

After the Phillies took the lead, Jonathan Bowlan pitched the bottom of the ninth and got the save. Mattingly learned during the game that All-Star closer Jhoan Duran was not available because of a stomach issue.

The win left the Phillies a game behind the Chicago Cubs for the top NL wild-card spot and three games ahead of San Diego, which holds the third spot.

Sosa’s heroics got Andrew Painter off the hook. The rookie right-hander had an ugly first inning. He allowed two hits, two walks and wild-pitched home two runs as the Angels went up 3-0 in the first inning.

Painter was brilliant over the next five innings, allowing just a walk.

Painter has shown much growth since his return from Triple A on July 31. But the first inning continues to be an issue. He has allowed seven first-inning runs in two of his last three starts. For the season, he has allowed 20 runs in the first inning for an ERA of 10.0.

“I’m happy with the way I bounced back,” Painter said. “It’s a common theme, struggling in the first inning. I have to figure it out. I hurt my chances to go deeper in the game.”

After Painter left, Jose Alvarado and Alex McFarlane pitched scoreless ball to keep the Phils in it until Joyce started handing out free passes in the ninth and Sosa cashed in.

Painter was in the clubhouse when Meckler robbed Stott for the second out in the ninth. He was also up there when Sosa drove his grand slam into the SoCal night.

“I was sitting here holding my head on Stott’s ball,” Painter said. “When Sosa hit his, I immediately went down to the dugout. Everybody loves Sosa. He came through. It was electric.”