Gunmen who attacked a mosque in Egypt's North Sinai on Friday brandished a so-called Islamic State flag as they opened fire through doorways and windows, killing more than 300 worshippers, including two dozen children, officials said.

No group has claimed responsibility but Egyptian forces are battling a stubborn IS 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 a 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.

State news agency MENA said the death toll had risen to 305, 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 IS 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."

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 IS consider targets because they revere saints and shrines, which for Islamists is tantamount to idolatry. IS has targeted Sufi and Shia 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.

Mr Sisi, a former armed forces commander who supporters see as a bulwark against Islamist militants, promised the "utmost force" against those responsible for friday's attack. Security has been a key reason for his supporters to back him, and he is expected to run for 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, without giving details on the number of militants.