By Ahmed Tolba and Patrick Markey

CAIRO, Nov 24 (Reuters) - Militants killed 305 people at a mosque in North Sinai on Friday, detonating a bomb and gunning down fleeing worshippers in the deadliest such attack in Egypt’s modern history, state media and witnesses said.

No group immediately claimed responsibility for the assault, but since 2013 Egyptian security forces have battled an Islamic State affiliate in the mainly desert region, and militants have killed hundreds of police and soldiers.

State media showed images of bloodied victims and bodies covered in blankets inside the Al Rawdah mosque in Bir al-Abed, west of El Arish, the main city in North Sinai.

Worshippers were finishing Friday prayers at the mosque when a bomb exploded, witnesses said. Around 40 gunmen set up positions outside the mosque with jeeps and opened fire from different directions as people tried to escape.

“Four groups of armed men attacked the worshippers inside the mosque after Friday noon prayers. Two groups were firing at ambulances to deter them, said Mohamed, a witness.

The death toll in the attack has risen to 305 killed, including 27 children, and 128 more people were wounded, MENA state news agency said on Saturday.

STRINGER via Getty Images View of the Rawda mosque, roughly 40 kilometers west of the North Sinai capital of El-Arish, after a gun and bombing attack, on November 24, 2017. (STRINGER/AFP/Getty Images)

Hours after the attack, Egypt’s military launched air strikes on targets in mountainous areas around Bir al-Abed, destroying vehicles and hideouts associated with the attack, the army said without giving numbers of militants killed.

“The armed forces and the police will avenge our martyrs and restore security and stability with the utmost force,” Egypt’s President Abdel Fattah al-Sisi said in a televised address.

“What is happening is an attempt to stop us from our efforts in the fight against terrorism, to destroy our efforts to stop the terrible criminal plan that aims to destroy what is left of our region.”

Striking at a mosque would be a shift in tactics for the Sinai militants, who have usually attacked troops and police and Christian churches.

Arabiya news channel and some 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.

The jihadists have also attacked local tribes and their militias for working with the army and police, branding them traitors.

Islamic State earlier this year posted a video of the beheading of two Sufis in northern Sinai, accusing them of practicing “sorcery.”

Anadolu Agency via Getty Images Wounded are taken to the hospital after the Egypt Sinai mosque bombing in Al-Arish, Egypt on November 24, 2017. (Photo by Stringer/Anadolu Agency/Getty Images)

SINAI BRANCH

The Sinai branch is one of Islamic State’s surviving branches following the collapse of its self-declared caliphate in Syria and Iraq after military defeats by U.S.-backed forces.

Sisi, a former armed forces commander who presents himself as a bulwark against Islamist militancy, convened an emergency meeting with his defense and interior ministers and intelligence chief soon after the attack.

Security has long been one of the key sources of public support for the former general, who is expected to run for re-election early next year for another four-year term.

U.S. President Donald Trump, in a post on Twitter on Friday, called the assault a “horrible and cowardly terrorist attack.”

“The world cannot tolerate terrorism, we must defeat them militarily and discredit the extremist ideology that forms the basis of their existence,” he added.

Trump later called Sisi to express his condolences and said the United States “stands byEgypt’s side in its fight against terrorism and is ready to strengthen cooperation with Egyptin this field,” according to a statement from Sisi’s office.

French Foreign Minister Jean-Yves Le Drian and British Foreign Secretary Boris Johnson also condemned the attack and expressed solidarity with Egypt.

Anadolu Agency via Getty Images A damaged car at the site of the Egypt Sinai mosque bombing in Al-Arish, Egypt on November 24, 2017. (Photo by Stringer/Anadolu Agency/Getty Images)

SINAI STRUGGLE

Egypt later said it would delay the opening of the Rafah border crossing to Gaza after the attack due to security concerns. The crossing had been due to open for three days beginning on Saturday.

North Sinai, which stretches from the Suez Canal eastwards to the Gaza Strip and Israel, has long been a security headache for Egyptian security forces because of smuggling.

Sisi has support from some Bedouin tribal leaders, who have helped the army locate weapon-smuggling routes used by jihadi groups, security officials said.

Local militant group Ansar Bayt al-Maqdis, once allied to al Qaeda, split from it and declared allegiance to Islamic State in 2014.

Bloodshed in the Sinai worsened after 2013 when Sisi led the overthrow of President Mohamed Mursi of the Muslim Brotherhood.

In July this year, at least 23 soldiers were killed when suicide car bombs hit two military checkpoints in the Sinai, in an attack claimed by Islamic State.

Militants have tried to expand their operations into Egypt’s heavily populated mainland, hitting Coptic Christian churches and pilgrims. In May, gunmen attacked a Coptic group traveling to a monastery in southern Egypt, killing 29.

(Additional reporting by Mohamed Abdellah and Eric Knecht in Cairo and Yousri Mohamed in Ismalia; Editing by Andrew Roche and Cynthia Osterman)