Gunmen attacked a crowded Egyptian mosque during prayers on Friday, blasting helpless worshippers with gunfire and rocket-propelled grenades and blocking their escape routes, in the deadliest-ever attack by Islamic militants in the country.

At least 235 people were killed before the assailants got away.

The attack in the troubled northern part of the Sinai Peninsula targeted a mosque frequented by Sufis, members of a mystic movement within Islam. Islamic militants, including the local affiliate of the Islamic State group, consider Sufis heretics because of their less literal interpretations of the faith.

Panic, confusion as victims rushed to ambulances 0:55

The startling bloodshed in the town of Bir al-Abd also wounded at least 109, according to the state news agency. It offered the latest sign that, despite more than three years of fighting in Sinai, the Egyptian government has failed to deter an Islamic State-led insurgency.

President Abdel-Fattah el-Sisi 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.

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 for months. Across the country, thousands have been arrested in a crackdown on suspected Islamists as well as against other dissenters and critics, raising concern about human rights violations.

Extremists attacked the al-Rawdah mosque, 40 kilometres from the North Sinai provincial capital of el-Arish, opening fire from five off-road vehicles on worshippers inside during the sermon, three police officers said. (Curious Maps)

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.

Friday's assault was the first major militant attack on a Muslim congregation, and it eclipsed past attacks, even dating back to a previous Islamic militant insurgency in the 1990s.

The militants descended on the al-Rouda mosque in four off-road vehicles as hundreds worshipped inside. At least a dozen attackers charged in, opening fire randomly, the main cleric at the mosque, Sheikh Mohamed Abdel Fatah Zowraiq said by phone from a Nile Delta town where he was recuperating from bruises and scratches suffered in the attack.

Relatives of Sheikh Sulieman Ghanem, 75, centre, surround him as he receives medical treatment at Suez Canal University hospital in Ismailia, Egypt, on Friday. (Amr Nabil/Associated Press)

He said there were explosions as well. Officials cited by the state news agency MENA said the attackers fired rocket-propelled grenades and shot men as they tried to run from the building. The militants blocked off escape routes with burning cars, three police officers on the scene said, speaking on condition of anonymity because they were not authorized to talk to the press.

Where was the army? It's only a few kilometres away. This is the question we cannot find an answer to. - Abdullah Abdel-Nasser, witness

Abdullah Abdel-Nasser, 14, who was attending prayers with his father, said the shooting began just as the cleric was about to start, sending panicked worshippers rushing to hide behind concrete columns or whatever shelter they could find. At one point, a militant shouted for children to leave, so Abdel-Nasser said he rushed out, though he was wounded in the shoulder by shrapnel and a bullet.

"I saw many people on the floor, many dead. I don't think anyone survived," he said at a hospital in the Suez Canal city of Ismailia, where around 40 of the wounded were taken, including many children.

Mohammed Ali said 18 members of his extended family were killed in the attack. The mosque belonged to a local clan, the Jreer, so many of its members worshipped there.

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

Some of the casualties in Bir al-Abd, where militants carried out a bombing and shooting attack on a Sufi mosque. ( EPA)

The attackers escaped, apparently before security forces could confront them.

Afterward, dozens of bloodied bodies wrapped in sheets were laid across the mosque floor, according to images circulating on social media. Relatives lined up outside a nearby hospital as ambulances raced back and forth. The state news agency MENA put the death toll at 235.

Resident Ashraf el-Hefny said many of the victims were workers at a nearby salt mine who had come for Friday services at the mosque.

"Local people brought the wounded to hospital on their own cars and trucks," he said by telephone.

Ambulances on the scene of the deadly bomb and shooting attack. (EVN)

No one claimed immediate responsibility for the attack. But the ISIS group affiliate has targeted Sufis in the past. Last year, the militants beheaded a leading local Sufi religious figure, the blind sheikh Suleiman Abu Heraz, and posted photos of the killing online.

Islamic State group propaganda often denounces Sufis. In the January edition of an ISIS online magazine, a figure purporting to be a high level official in the Sinai affiliate of the group vowed to target Sufis, accusing them of idolatry and heretical "innovation" in religion and warning that the group will "not permit (their) presence" in Sinai or Egypt.

Millions of Egyptians belong to Sufi orders, which hold sessions of chanting and poetry meant to draw the faithful closer to God. Sufis also hold shrines containing the tombs of holy men in particular reverence.

Islamic hardliners view such practices as improper, even heretical, and militants across the region often destroy Sufi shrines, saying they encourage idolatry because people pray to the figures buried there for intercession.

Egypt will "face terrorism with all our strength," says Abdel Fattah el-Sisi 0:28

El-Sisi convened a high-level meeting of security officials as his office declared a three-day mourning period.

In a statement, he said the attack would only "add to our insistence" on combating extremists. Addressing the nation later on television, he said Egypt is waging a battle against militancy on behalf of the rest of the world, a declaration he has often made in seeking international support for the fight.

U.S. President Donald Trump denounced what he called a "horrible and cowardly terrorist attack on innocent and defenceless worshippers."

"The world cannot tolerate terrorism" he said on Twitter, "we must defeat them militarily and discredit the extremist ideology that forms the basis of their existence!" He later tweeted that he would call el-Sisi and said the attack showed the need to get "tougher and smarter," including by building the wall he has promised along the U.S. border with Mexico.

Prime Minister Justin Trudeau issued a statement saying he was "shocked and horrified" by the attack.

Full statement on today’s terrorist attack in Egypt: <a href="https://t.co/MU7Htk6zXS">https://t.co/MU7Htk6zXS</a> —@JustinTrudeau

Islamic militants stepped up their campaign of violence in northern Sinai after the military ousted the elected but divisive Islamist Mohammed Morsi from power in 2013 and launched a fierce crackdown on Morsi's Muslim Brotherhood group.

The result has been a long, grinding conflict centred on el-Arish and nearby villages. The militants have been unable to control territory, but the military and security forces have also been unable to bring security, as the extremists continuously carry out attacks.

The attacks have largely focused on military and police, killing hundreds, although exact numbers are unclear as journalists and independent investigators are banned from the area. The militants have also assassinated individuals the group considers spies for the government or religious heretics.

Egypt has also faced attacks by militants in its Western Desert.