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

CAIRO — At least 305 people were killed when gunmen opened fire and bombed a mosque in Egypt's volatile Sinai Peninsula on Friday. Government officials said 128 more had been injured in the attack — among the deadliest in Egypt's history.

The rising death toll included 27 children, officials said.

Images from inside the building showed dozens of bodies wrapped in blood-soaked cloth lined up on the carpeted floor.

Police sources told The Associated Press that men in four off-road vehicles opened fire on worshippers in the al-Rawdah mosque in the town of Al Rawdah. NBC News could not immediately independently verify that account.

Two eyewitnesses and a security source told Reuters that the suspected militants targeted supporters of the security forces attending prayers. Citing official sources, the state-run MENA news agency reported that the mosque is largely attended by Sufi Muslims — a form of Islam considered heretical by some conservatives and extremists like the Islamic State group.

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

Around 50 ambulances were transferring victims to hospitals, according to the Ministry of Health. A statement issued by Egypt's General Prosecutor Nabil Sadiq put the death toll at 305, with at least 128 others wounded.

A Health Ministry official told Al Jazeera TV that “there were many people inside the mosque — it’s only a small mosque."

Gunmen shot worshippers fleeing the initial attack, he added.

People sit next to bodies of worshippers killed in Friday's mosque attack. EPA

There has been a wave of attacks on the country's Coptic Christian minority, but strikes on mosques are rare and Friday's onslaught shocked many throughout Egypt.

While Egypt's security forces have been battling Islamist militants in northern Sinai for years, violence picked up after the 2013 ouster of President Mohammed Morsi. A new group called Ansar al-Islam claimed responsibility for a bloody October attack on Egyptian police.

The conflict has killed hundreds of soldiers and militants over the years, although journalists are banned from the area and exact numbers are unclear.

President Abdel-Fattah el-Sissi declared three days of mourning and called a meeting of security officials after the attack.

People outside a mosque that was attacked in Bir al-Abed, west of Arish city, Sinai Peninsula, Egypt, on Friday. EPA

"I reiterate my condolences to the families of the martyrs, and my wishes for a recovery of the wounded people," el-Sissi said on state television. "Once again I tell all Egyptians that this situation, what happened will increase our determination to face terrorism with all our strength."

El-Sissi's office said U.S. President Donald Trump offered the United States' condolences.

In a tweet, Trump called the attack "horrible and cowardly."

"The world cannot tolerate terrorism, we must defeat them militarily and discredit the extremist ideology that forms the basis of their existence!" Trump tweeted. He followed up with another tweet saying he planned to call el-Sissi later on Friday, and renewed his call for a border wall and travel ban.

Will be calling the President of Egypt in a short while to discuss the tragic terrorist attack, with so much loss of life. We have to get TOUGHER AND SMARTER than ever before, and we will. Need the WALL, need the BAN! God bless the people of Egypt. — Donald J. Trump (@realDonaldTrump) November 24, 2017

The U.S. State Department called the attack "an unconscionable act of evil," and the United Nations Security Council issued a statement of condemnation.

Charlene Gubash reported from Cairo. F. Brinley Bruton reported from London.