Yesterday, Egypt suffered its worst mass killing since at least 2013 – a massacre that was ironically carried out by the country’s security forces – when five armed gunmen stormed a mosque in northern Sinai and killed more than 300 people, including at least two dozen children.

And while no group has stepped up to take responsibility for the murderous rampage, Reuters reported that the attackers brandished an Islamic State flag, according to witness accounts. Prosecutors are already investigating the group.

Egyptian forces are battling a stubborn Islamic State affiliate in the region, one of the surviving branches of the militant group after it suffered defeats by US-backed forces in Iraq and Syria.

The assault on the mosque has stunned Egyptians, prompting President Abdel Fattah al-Sisi’s government to tighten security at places of worship and key buildings, and call three days of mourning for the bloodiest attack in Egypt’s modern history. The official death toll rose to 305 Saturday, including 27 children, and 128 people were injured.

Egypt’s public prosecutor’s office, citing interviews with wounded survivors as part of its investigation, linked Islamic State militants, also known as Daesh, to the attack on the Al Rawdah mosque in Bir al-Abed, west of El-Arish city.

“The worshippers were taken by surprise by these elements,” the prosecutor said in a statement. “They numbered between 25 and 30, carrying the Daesh flag and took up positions in front of the mosque door and its 12 windows with automatic rifles."

Witnesses described a scene of unparalleled brutality, amplified by the notion that the attackers escaped before authorities could respond.

The gunmen, some wearing masks and military-style uniforms, had arrived in jeeps, surrounded the mosque and opened fire inside, sending panicked worshippers scrambling over each other to escape the carnage. Witnesses had said gunmen set off a bomb at the end of Friday prayers and then opened fire as people tried to flee, shooting at ambulances and setting fire to cars to block roads. Images on state media showed bloodied victims and bodies covered in blankets inside the mosque. “When the shooting began everyone was running, and everyone was bumping into one another,” Magdy Rezk, a wounded survivor, said from his hospital bed. “But I was able to make out masked men wearing military clothing."

Striking a mosque would be a shift in tactics for the Sinai militants, who have previously attacked troops and police and more recently tried to spread their insurgency to the mainland by hitting Christian churches and pilgrims.

Local sources said some of the worshippers were Sufis, whom groups such as Islamic State consider targets because they revere saints and shrines, which for Islamists is tantamount to idolatry. Islamic State has targeted Sufi and Shi‘ite Muslims in other countries like Iraq.

The jihadists in Egypt’s Sinai have also attacked local tribes and their militias for working with the army and police.

El-Sisi, a former armed forces commander who has predicated his rule on a law-and-order platform and opposition to Islamist militants, has promised to exercise the “utmost force” against those responsible for Friday’s attack.

Finding the attackers will probably be an important priority for el-Sisi as he seeks re-election next year.

Egypt’s military carried out air strikes and raids overnight to target hideouts and vehicles involved in the attack, the army said, but didn’t specify how many militants were killed.

“What is happening is an attempt to stop us from our efforts in the fight against terrorism,” Sisi said on Friday.

North Sinai, a mostly desert area stretching from the Suez Canal eastwards to the Gaza Strip and Israel, has been the location of some of the most extreme militant violence in Egypt. Local militant group Ansar Bayt al-Maqdis, once allied to al Qaeda, split from it and declared allegiance to Islamic State in 2014. But attacks in the Sinai worsened after 2013 when Sisi led the overthrow of President Mohamed Mursi of the Muslim Brotherhood after mass protests against his rule.

Since seizing power, el-Sisi has enforced a media blackout in the country’s most troubled region as he and his government hope to draw more foreign investment and finish an IMF reform program to help revive an economy that struggled through instability after the 2011 uprising ousted long-standing leader Hosni Mubarak.