CAIRO, Egypt — Witnesses to an attack outside a Coptic Christian church in Egypt that left nine people dead said it was residents and worshippers, not police, who kept the death toll from soaring even higher. One man in particular — a 53-year-old resident who pounced on the gunman as he was reloading his automatic rifle — likely saved dozens of lives.

Police initially were praised for their quick response to the attack Friday on the church and a nearby Coptic Christian-owned store, but witnesses told The Associated Press that the deadly assault lasted 20 minutes and it took another 10 minutes before police arrived and shot and wounded the assailant.

Worshippers slammed the church’s iron gate closed to prevent the assailant from entering and killing more people, the witnesses said Sunday. They credited the brave actions of the man who jumped the gunman as he was reloading his AK-47 with preventing an even worse bloodbath.

The accounts painted a picture of Christian-Muslim unity in the face of danger as courageous residents pelted the assailant with rocks as he fled the church after the attack, occasionally pausing to fire warning shots from his automatic weapon.

The attack began around 10:30 a.m. when Mass at the Mar Mina church in the southern Cairo suburb of Helwan had just finished and worshippers were starting to make their way home.

Magdy Adel, a 65-year-old Christian retiree who runs a stationary store near the church, sheltered five worshippers who took cover inside his shop — three elderly women, an elderly man and a middle-aged woman. He pulled down the store’s shutters and hid on the sidewalk behind a car to keep an eye on the attacker.

“The terrorist was very agitated when they closed the church’s iron gate and he could not go inside,” Adel said. “He had a lot of ammunition and kept shooting at the gate, killing some people inside.”

Another witness, Mustafa Mahmoud, was on the street a short distance from the church when the assailant opened fire. At first he thought the gunman was a plainclothes officer assigned to guard the church but he quickly found out otherwise.

“His first victim was a policeman guarding the church. He shot him but did not instantly kill him. A young man who rushed out from the church was killed right away. When a second policeman emerged, he shot him in the leg, and he was dragged back inside the church by worshippers,” Mahmoud said.

“Later, the terrorist finished off the first policeman with a few shots to the chest,” said the 39-year-old computer engineer and father of two.

The Christian owner of a store that sells wooden coffins — Mahmoud only knew his first name, Wadie — was shot dead, and when his wife ran out of the church to check on him she was shot dead too.

“Their daughter was shot and wounded,” he added.

Mahmoud said the gunman later moved away to look for the motorbike he rode to the site, but residents had by then hidden it to deny him a getaway. “He still had ample chance to get away but seemed not to want to. He was either suicidal or deranged,” he said.

Mahmoud was among dozens of men who pursued the gunman, taking shelter behind cars and inside building entrances to avoid being shot. When the assailant was pinned to the ground by a man identified by local media as 53-year-old Salah el-Mougi they rushed toward the assailant.

“We all hit him, and I was about to smash his head with a rock, but the police wanted him alive and they fired in the air to disperse us,” said Mahmoud.

The assailant was shot and wounded by a senior police officer, according to local media accounts.

One video posted on social media Sunday showed the final minutes before the gunman was shot. Wounded in the leg and shoulder, he sat up and appeared to be reloading his rifle when el-Mougi pounced on his back.

“That was divine luck. He would have shot me had I hesitated for a second,” el-Mougi told the pro-government Seventh Day newspaper, adding that he wanted to prevent the assailant from potentially using a suicide belt or explosives.

The attack was claimed by the Islamic State group, whose local affiliate is spearheading an insurgency in Egypt’s Sinai Peninsula that has in recent months grown in sophistication and brutality.

IS militants have specifically targeted Egypt’s Coptic Christian minority since December 2016, with a series of church bombings that have killed more than 100 and wounded scores. On Dec. 22, a large mob of Muslims shouting anti-Christian slogans stormed an unlicensed church south of Cairo, assaulting worshippers and destroying furniture and fittings. Three people were injured.

Christians make up about 10 percent of Egypt’s population. They have long complained of discrimination in the Muslim-majority nation and that authorities don’t do enough to protect them.