President Abdel Fattah el-Sisi vowed to respond to the attack on al Rawdah mosque with "brute force." Some 109 others were injured, Egyptian state media reported.
No one has claimed responsibility, but the strike bears the hallmarks of an attack by ISIS.
The mosque is known as the birthplace of an important Sufi cleric. Sufism is a mystical branch of Islam that some ultra-orthodox Muslims consider heretical.
Coordinated attack: Gunmen fired on people fleeing after explosions took place at the mosque between Bir al-Abed and the city of al-Arish. The attackers also opened fire on ambulances, witnesses said.
The target: The mosque is known for being the birthplace of Sheikh Eid al-Jariri, a Sufi cleric considered the founder of Sufism in the Sinai Peninsula.
Egypt's reaction: The President vowed to restore security and avenge those killed.
'Ambush' followed blasts
Blasts from improvised explosive devices caused considerable damage to the mosque, Ahram Online said.
The attack started when an explosive went off in a building adjacent to the mosque, and gunmen fired at worshippers as they fled, eyewitnesses told CNN.
Ashraf Abu Salem 27, said gunmen then went inside the mosque to fire at people. Entering the mosque afterward, he said the bodies looked as if people had been shot in the back. His clothes were stained with the blood of the injured he helped to carry out, but he was unharmed.
The gunmen had set up "ambush" locations and opened fire on ambulances as they were transporting wounded worshippers to al-Arish before the arrival of security services, eyewitnesses reported.
Photos from inside the mosque showed what appeared to be bodies lined up in rows on the carpet.
Osama, who didn't want his last name used, drove one of the first ambulances to the scene. He said he turned around after shots were fired at the vehicle. Ambulances from al-Arish managed to reach the mosque only after security forces secured the road, he said.
The attackers used automatic weapons, said Diaa Rashwan, the chairman of the state information service. Some victims were also killed by the explosions.
Three days of national mourning
In a short, televised speech after meeting with security officials, Sisi said, "We will respond to this act with brute force against these terrorists. This terrorist act will strengthen our resolve, steadfastness and will to stand up to, resist and battle against terrorism."
The presidency has declared three days of national mourning.
"Egypt is facing terrorism on behalf of the region and the world," Sisi said.
Sisi met with several of his top ministers, according to the Ministry of Interior Facebook page. He affirmed his confidence that Egypt is capable of winning the war against terrorism and eradicating it, a spokesman said.
Sisi has expressed concern recently that as ISIS militants flee Iraq and Syria they will come to Egypt.
Ahmed Al-Tayeb, a top Sunni imam, told a nationwide television audience that the Al-Azhar Mosque supports the country's leadership and the military against the terrorism groups, which he said have a false understanding of Islam.
He said the terrorists killed innocent people, did not distinguish between children, youth or elders, and the attack was a war crime.
Hints of ISIS responsibility
There is no word yet on what happened to the militants involved.
Egyptian security forces face almost daily attacks from ISIS-aligned militants, whom they have been battling in northern Sinai for years. However, mosque attacks are relatively rare in Egypt.
In October 2015, 224 people were killed
when a bomb brought down a Russian passenger jet that crashed in the Sinai Peninsula. ISIS' affiliate in Egypt claimed that attack
Leaders around the world condemned the mosque attack.
US President Donald Trump called it a "horrible and cowardly terrorist attack on innocent and defenseless" worshippers in Egypt and said terrorism and its ideology must be defeated.
The White House also said in a statement that "the international community must continue to strengthen its efforts to defeat terrorist groups that threaten the United States and our partners and we must collectively discredit the extremist ideology that forms the basis of their existence."
According to both nations, Trump reiterated Washington's solidarity with Egypt in its terror fight during a call with Sisi. The Egyptian President stressed the importance of concerted international efforts to combat terrorism, his office said.
UK Foreign Secretary Boris Johnson said he was deeply saddened by the "abhorrent attack." "My sincere condolences to all those affected by such a barbaric act," he tweeted.
UK Prime Minister Theresa May and French President Emmanuel Macron also gave their condolences on Twitter, while NATO Secretary General Jens Stoltenberg said his thoughts were with all those affected.
On the Jordanian royal family's official Twitter account, King Abdullah II condemned what he called a "heinous terrorist attack."
"We stand with Egyptians in their war against terrorism and against anyone who tries to harm the Egyptian national security," Palestinian Authority President Mahmoud Abbas said in a statement.
UN Secretary-General Antonio Guterres called "for those responsible for today's horrific attack to be swiftly brought to justice."
European Parliament President Antonio Tajani tweeted: "Heartbreaking loss of life in the cowardly massacre that took place in Egypt. Acts of barbarism and hatred in the name of God are acts against God himself."