Updated

The deadly attack outside a church in Egypt lasted up to 20 minutes and it was another 10 more minutes before police shot and wounded the assailant, according to witnesses who spoke to The Associated Press on Sunday.

Local media initially effusively praised the police's "alertness" during Friday's attack on the church and a nearby Coptic Christian-owned store that left at least nine people dead, saying they prevented it from turning into a larger massacre. Witnesses, however, said it was the residents and worshippers that may have prevented a much higher death toll.

Worshippers, mindful in the fog of the attack, closed the church's iron gate to prevent the assailant from entering and killing more people, said the witnesses. The brave actions of a 53-year-old resident who pounced on the gunman as he was reloading his automatic rifle likely also saved dozens of lives, they added.

The witness accounts of Friday's attack in the southern Cairo suburb of Helwan, together with others published in local media, paint a picture of Christian-Muslim unity in the face of danger. Courageous residents pelted the assailant with rocks and soda cans as he walked away from the church, occasionally pausing to fire warning shots from his AK-47 rifle.

Egypt Attack 1

In this Friday, Dec. 29, 2017 file photo, people gather in front of Mar Mina church after a deadly attack claimed by the Islamic State group, in Helwan, Cairo, Egypt. (AP Photo/Amr Nabil)

The attack began around 10:30 a.m. when Mass at the Mar Mina church had just finished and some worshippers were already making their way home. The church sits on the street level of a three-story building. The other two house Sunday schools and meeting rooms.

Magdy Adel, a 65-year-old Christian retiree who runs a stationary store near the church, sheltered five worshippers — three elderly women, one elderly man and a middle aged woman — who took cover in his shop. 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," he 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 away from the church when the gunman opened fire. When he first saw the gunman, he thought he was a plainclothes policeman assigned to guard the church. It was not long before he 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 to keep him out of harm's way."

"Later, the terrorist finished off the first policemen with a few shots to the chest," said Mahmoud, a 39-year-old father of two who works as a computer engineer.

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

Egypt Attack 2

In this Friday, Dec. 29, 2017 file photo, a policeman stands guard in front of Mar Mina church after a deadly attack claimed by the Islamic State group, in Helwan, Cairo, Egypt. (AP Photo/Amr Nabil)

"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," Mahmoud said.

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

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

The assailant was shot 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. "I wanted to prevent him from 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 last year, with a series of church bombings that killed more than 100 and wounded scores. A large mob of Muslims shouting anti-Christian slogans stormed an unlicensed church south of Cairo on Dec. 22, assaulting worshippers and destroying furniture and fittings. Three were hurt.

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.