Last Friday was a bad day for police in Upper Darby, Pennsylvania, which hugs the western border of Philadelphia.

When Upper Darby High School lets out for the day, anywhere from six to eight township officers are tasked with patrolling the area as 4,000 students pour from the building.

Things don’t usually get problematic, but on Friday more than a few kids wanted to fight.

Cops responded to fisticuffs at three nearby locations, Philly.com reported — but one in particular got dangerous for an officer.

This fight between two teen boys drew a large crowd, but when the officer stepped in and pulled one kid off, the other teen jumped the cop, Upper Darby Police Superintendent Michael Chitwood told Philly.com.

“Now he’s fighting two of them and he’s calling for an assist officer at the same time,” Chitwood added to the outlet — but that was nothing compared to what was unfolding.

“There’s a crowd of 40 or 50 kids watching the fight, and they all move in toward the officer,” he explained, adding that ”there’s no doubt they would have attacked him.”

Fortunately for the outnumbered cop, a resident who lives on the block emerged from his house holding a gun and telling the teens to stop.

Image source: Shutterstock

Image source: Shutterstock

And wouldn’t you know — they took heed of his command.

“He had the gun in his hand, but he didn’t point it at the kids, he just told them to back off,” Chitwood told Philly.com.

The surrounded officer suffered hand injuries, the outlet said — but Chitwood said it could have been a lot worse, noting that if the ”good Samaritan” resident hadn’t stepped up, the officer would have been “dead meat.”

The gun owner, 35, is a concealed-carry permit holder, Chitwood added to the outlet, and he put a lid on the rumbling teens until other officers got there and took control.

Philly.com added that an officer who responded to the call for help was kicked by one of the teens in the fight and suffered a serious leg injury — but it isn’t clear if that occurred before or after the resident stepped in.

The two teens from the fight in question were charged with aggravated assault on police, riot, harassment, and related offenses, Philly.com reported, adding that they were taken to a juvenile detention center. Six other teens were arrested for fighting that day; one was taken to a juvenile detention center and the other five were released to parents or guardians. Six of the teens arrested attend Upper Darby High School and the other two attend two other schools.

Since Friday’s incident, police told Philly.com that after-school patrols in the area have doubled.

“There’s thousands of kids that walk to and from that school without a problem,” Chitwood told the outlet, “but every once in a while you get these wannabe gangsters, and if they want to be gangsters, we’ll treat them like gangsters.”