The mosque was packed with hundreds of worshipers 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 Islamic State 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 Islamic State, 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 worshipers, including dozens of children.

By the time the shooting stopped, many of the village’s men were lifeless. No group has claimed responsibility.

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-hard-line Islamists are shifting tactics and picking new targets is worrying for Egypt, where governments have struggled to contain groups far less brazen than Islamic State.

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.