Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

CAIRO — The small town of Al Rawdah in Egypt's volatile Sinai Peninsula was thrust into the international spotlight Saturday after 305 people were killed in one of the deadliest attacks by Islamist extremists in the country's modern history.

At least 27 children were among the dead and another 128 people were wounded after militants opened fire on unsuspecting worshipers who had gathered at the al-Rawdah mosque for Friday prayers, Egyptian chief prosecutor Nabil Sadeq said Saturday.

The attack offered the latest sign that, despite more than three years of fighting in Sinai, the Egyptian government has failed to deter an insurgency led by the Islamic State, also known as ISIS. Egyptian President Abdel-Fattah el-Sissi vowed that the attack "will not go unpunished" and that Egypt would persevere with its war on terrorism, but he did not specify what new steps might be taken.

He ordered Saturday for a mausoleum to be built in memory of the victims of the attack.

The militants, estimated to be a group of 25 to 30, arrived in SUVs Friday wielding machine guns. They positioned themselves at the entrance and at the mosque's 12 windows before firing indiscriminately into the crowd, Sadeq said in a statement.

The imam had barely made it into the pulpit to deliver his sermon when the gunfire rang out, Sadeq added. Mass panic then ensued as worshipers desperately looked for a way to escape.

Related: Egypt mosque attack leaves at least 305 dead in Sinai Peninsula

Mohamed Salah, a local teacher, said he lost more than 20 friends, colleagues, students and relatives in the attack. He spent most of the day on Friday and Saturday in hospitals aiding victims and hearing their stories.

They told him that masked men in military fatigues carrying black ISIS flags exited four cars and began firing automatic weapons indiscriminately and threw hand grenades into the mosque.

"They came from different directions and sprayed bullets with automatic weapons. Whoever fled outside they killed," Salah said he was told. "The whole thing lasted 45 minutes to an hour. It's a real massacre. The mosque was filled with bodies, blood and blood on the carpets. And in the hospital there are people in bad shape."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Witnesses told Reuters that the militants kept firing 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.

A victim being taken care of in a hospital in Ismailia, some 200 kilometers South West of al-Arish, Egypt on Nov. 24 2017. EPA

"When the shooting began everyone was running, and everyone was bumping into one another," Magdy Rezk, a wounded survivor, told the news agency from his hospital bed. "But I was able to make out masked men wearing military clothing."

Another witness, Mohammed Ali, told The Associated Press that 18 members of his extended family were killed in the attack.

"Where was the army? It's only a few kilometers away. This is the question we cannot find an answer to," he said.

The attackers brandished the black flag of ISIS, the chief prosecutor said.

"Where was the army? ... This is the question we cannot find an answer to."

The attack targeted a mosque frequented by Sufis, members of a mystic movement within Islam. Islamic militants, including the local affiliate of ISIS, consider Sufis heretics because of their less literal interpretations of the faith.

"They threatened it before," Salah said, referring to ISIS. "This is a well-known Sufi mosque. They (the members of the mosque) told the army (about the threat). It's known that after Friday prayer they have dinner together and socialize."

The military is known to maintain numerous checkpoints in the area, and Salah said anyone going to the mosque would have likely had to pass through one.

No one claimed responsibility for the massacre but the ISIS group affiliate has targeted Sufis in the past.

The ministry of defense said Saturday that it was continuing to search for the perpetrators of the attack and released videos purporting to show Egyptian airstrikes targeting militants' weapons and ammunition stores.

People stand outside Al Rawdah mosque after an attack in Bir Al-Abed, Egypt on Nov. 25, 2017. Mohamed Soliman / Reuters

The military also said it had targeted several vehicles in which some of the culprits of the attack were traveling, according to the AP. All passengers of the vehicles were killed, it added.

NBC News could not verify these accounts.

The military and security forces have already been waging a tough campaign against militants in the towns, villages and desert mountains of Sinai, and Egypt has been in a state of emergency since April.

Across the country, thousands have been arrested in a crackdown on suspected Islamists as well as against other dissenters and critics, raising concerns about human rights violations.

Seeking to spread the violence, militants over the past year have carried out deadly bombings on churches in the capital of Cairo and other cities, killing dozens of Christians.

The ISIS affiliate is also believed to be behind the 2016 downing of a Russian passenger jet that killed 226 people over Sinai.

Charlene Gubash reported from Cairo and Saphora Smith reported from London.