A 25-year-old man was threatened at gunpoint and zip-tied Sunday night by a pair of would-be robbers outside his Mayfair apartment, but managed to break free, grab his legally owned handgun from his waistband, and fire at his attackers, killing one as the other ran away, police said.

The man’s assailants were wearing ski masks and fake police badges when they approached him with guns around 10 p.m., police said.

The attempted robbery was another violent incident in a four-day stretch marked by gunfire. At least 55 people were killed or wounded in the city in shootings between Thursday and Sunday, according to an Inquirer analysis of police statistics, making that one of the worst four-day stretches of gun violence in the city since 2015.

Ten of those victims died, the analysis shows, including three males — ages 17, 22, and 25 — fatally shot in separate incidents in the course of three hours Saturday afternoon. Authorities provided few details about the crimes and said none had resulted in arrests.

The shootings came as gunfire broke out in other communities across the country: In Pittsburgh, two teens were killed and at least eight others were injured when more than 90 shots were fired at a house party early Sunday morning. More than a dozen people were shot in a series of incidents in Chicago. And in South Carolina, authorities said, there were two mass shootings over the holiday weekend — one at a mall that left 14 injured, another at a restaurant that wounded nine.

At Philadelphia City Hall on Monday, a half-dozen advocates and State Sen. Art Haywood staged a sit-in outside Mayor Jim Kenney’s office, demanding a more urgent and cohesive response to the gun violence crisis.

Haywood, a Democrat who represents parts of Philadelphia and Montgomery Counties, said he’s asked to meet the mayor — without success — three times since last year to discuss violence-prevention tactics that other cities have tried. The group plans to sit in at City Hall every day until Kenney meets with them, he said.

“The strategy is not coordinated,” Haywood said. “And I’m seeing an increasing level of hopelessness that we have to address.”

Already this year, 140 people have been slain in homicides in Philadelphia, police statistics show, a slight decrease compared with last year’s record-setting pace, but well above the year-to-date total in much of the city’s recent history. An additional 500 people have been wounded in shootings in 2022, the statistics show.

District Attorney Larry Krasner said at a weekly news conference Monday that it was “a pretty terrible weekend in Philadelphia.”

“Shooting victims were aged as young as 3 years old up to senior citizens,” Krasner said.

Police said the attack in Mayfair happened on the 7200 block of Battersby Street around 10 p.m. Homicide Capt. Jason Smith said a resident of an apartment had just parked his Dodge Hellcat when he was approached by two men who identified themselves as police officers, bound his hands with zip-ties, held a gun to his back, and started walking him toward his apartment. One of the men was wearing a gold badge that hung around his neck, Smith said.

Before they got inside, the resident — whom police did not identify — managed to break one hand free of the zip-tie and reach for his gun, Smith said. He fired several shots, striking one of the attackers in the head, arm, and chest. The second suspect ran away, while Smith said the resident — who had a license to carry a firearm — went into his apartment and barricaded his door with furniture.

The man who was shot was taken to Jefferson-Torresdale Hospital and pronounced dead at 10:19 p.m., police said. Smith said police recovered nine fired cartridge casings at the scene, though it was not clear if all were from the resident’s gun.

Smith said investigators were not sure what the robbers may have been looking for, or whether they knew the man they attacked.

“We don’t know why he was targeted,” he said.

Smith said he did not expect the man who fired at his assailants to face charges. Krasner and Assistant District Attorney Joanne Pescatore, supervisor of the DA’s Homicide and Non-Fatal Shooting Unit, declined to offer details on the case, citing an ongoing investigation.

In Mayfair on Monday, few signs remained of the chaos from the night before.

Steve Schaefer, who lives across a three-foot alleyway from where the shooting happened, said he was in his bedroom Sunday night when he heard five to six loud banging noises around the same time. He said he and his brother went out moments later to see the door to his neighbor’s apartment ajar as police converged on the scene.

Denise McGlinchey, who lives a few doors away, said Monday that she had been relaxing Sunday night when she heard loud noises outside her window. She didn’t think anything of it — until police arrived.

”It was crazy,” she said.

Graphics editor John Duchneskie and staff writers Mensah M. Dean and Anna Orso contributed to this article.