ISMAILIA, Egypt — The mosque was packed with hundreds of worshippers for Friday prayers in Egypt's North Sinai when gunmen in military-style uniforms and masks appeared in a doorway and at windows.
The ease with which they mounted an attack — killing more than 300 people in the worst bloodshed of its kind in Egypt's modern history — highlighted the threat militant groups pose in the most populous Arab country.
After four years of battling ISIS in the Sinai, where the group has killed hundreds of soldiers and police, authorities still face an enemy with growing ambitions in Egypt, despite its defeats in Iraq, Syria and Libya.
Carrying the black flag of ISIS, the assailants arrived in off-road vehicles before opening fire on the cream-colored Al Rawdah mosque in Bir al-Abed, leaving its carpets stained with blood, officials and witnesses said.
People scrambled to escape as gunmen opened fire at worshippers, including dozens of children. By the time the shooting stopped, many of the village's men were lifeless.
No group has claimed responsibility.
ATTACK RATTLES EGYPTIANS
Egyptians were stunned because the attack was directed at a mosque - a rarity in the country's history of Islamist insurgencies.
The possibility that ultra-hardline Islamists are shifting tactics and picking new targets is worrying for Egypt, where governments have struggled to contain groups far less brazen than ISIS.
Egyptian leaders have adopted a zero-tolerance policy, with air strikes, raids on militant hideouts and long prison sentences.
President Abdel Fattah al-Sisi has once again threatened to crush the militants.
"The armed forces and the police will avenge our martyrs and restore security and stability with the utmost force in the coming period," he said after Friday's carnage.
Sisi has called for a comprehensive campaign to counter what he describes as the existential threat of radical jihadism, deploying moderate clerics to promote moderate Islam, for instance.
He is expected to run for a second term early next year. Even with a convincing win, he will face pressure to deliver on promises of stability, especially if attacks like that on Al Rawdah persist.
For ISIS, the village was a target because of its ties to Sufism, a mystical form of Islam that hardline Islamist groups consider heretical.
Some villagers recalled how these threats were made about a year ago in an ISIS internet publication.
In a December 2016 issue of al-Nabaa, one of the group's religious leaders left little doubt that Sufis would be targeted. It mentioned Al Rawdah directly.
"Our primary focus lies in the war against polytheism and apostasy, and of those, Sufism, sorcery and divination," he said. More threats were made in early 2017.
SUFIS CONDEMNED FOR BELIEFS
In March, ISIS's branch in the Sinai posted a video of its religious police forcing a group of Sufis to renounce their beliefs under threat of death.
It showed what it said were militants beheading two elderly Sufi men in the desert after they were found guilty of witchcraft and sorcery.
Egypt has about 15 million Sufis, and their shrines and saints appear in villages across the country.
Ultra-conservative Salafists abhor Sufi practices and some have in the past threatened to smash their symbols with hammers and iron bars.
Five police and army sources said there was no recent specific threat against Sufis in Al Rawdah.
Friday's attack began in the early afternoon.
The mosque's imam said he had just stepped onto the podium for his sermon when gunfire erupted and worshippers struggled to escape.
"I found people piled on top of each other and they kept firing at anyone," imam Mohamed Abdel Fattah told Reuters from his hospital bed in Sharqiya city. "They fired at anyone who breathed."
Ramadan Salama, 26, said all he remembers before ending up in hospital was gunmen entering the mosque during the sermon and spraying worshippers with gunfire.
As Egyptian security forces try to reassure an anxious public, they face yet another dangerous enemy.
A new group with military training is already posing a more complex threat. In October it mounted a sophisticated attack, not far from Cairo.
The little-known Ansar al-Islam claimed responsibility for the attack on police in the Western desert, far from northern Sinai. Security sources said dozens of police officers and conscripts were killed. The government said 16 police and conscripts died.
Security sources said the heavy weapons and tactics employed indicated ties to ISIS or more likely an al Qaeda brigade led by Hesham al-Ashmawy, a former Egyptian special forces officer turned jihadist.
For now, security and intelligence officials will continue to hunt Ashmawy, described as the country's most wanted man.
Egypt's prosecutor's office, citing its investigation and interviews with wounded survivors, says gunmen carried an ISIS flag as they stormed the Al Rawdah mosque.
Authorities say 305 people, including 27 children, died as gunmen even attacked ambulances arriving on the scene. Another 128 were wounded.
"They entered the mosque from outside, almost 10 to 20 people with weapons, and they destroyed everything," said resident Magdy Rezk from hospital.
It was a huge toll for a tiny village. Tribal leader Ibrahim el-Menaie, told Reuters via social media that it has a population of only 800.
"The whole village is black with mourning," said resident Haj Ahmed Swailam.