The brazen attack on worshipers at an Egyptian mosque early Friday showed the ability of the Islamic State’s regional affiliates to inflict death and exact revenge for the loss of the group’s main enclaves in Iraq and Syria.

There were no immediate claims of responsibility for the attack on the al-Rawda mosque in Egypt’s sparsely populated Sinai Peninsula, but there were many reasons to suspect that the Islamic State was responsible.

The Egyptian affiliate, which consists of up to 1,000 members, in recent months has stepped up attacks on Egyptian soldiers and police in the region and laid siege to Coptic Christian churches. Before Friday's attack, the group was best known for its suspected role in the downing of Russia's Metrojet Flight 9268 in 2015, which killed 224 Russian tourists.

The attack on Friday represented a shocking escalation in the carnage, with Egyptian officials reporting 235 dead. It also represented a new and risky kind of target for the Islamic State’s Egyptian affiliate. The Egyptian branch of the Islamic State appeared to be targeting fellow Sunni Muslim civilians at prayer.

In the wake of the bloodshed, government officials and outside analysts were puzzling over the strategy behind the group’s latest horror.

The Sinai chapter is only a part of a larger constellation of regional affiliates, and its high-profile attack could be a sign of a broader power struggle to take up the Islamic State’s leadership mantle now that the group’s self-declared caliphate has been destroyed, intelligence officials and terrorism experts said. Several local cells already have begun preparations to continue or even intensify their fight, analysts said.

“The Sinai attack underscores that the elimination of the ISIS caliphate will have little effect on the group’s regional affiliates, whose success or failure depends on local conditions,” said Daniel Benjamin, a former coordinator for counterterrorism at the State Department and a professor at Dartmouth College. The Sinai branch, like most of the regional chapters, existed long before the Islamic State declared the establishment of its caliphate in 2014.

To other analysts, the timing of the attack, which occurred during Friday prayers, and the choice of target, a Sufi mosque, reflected a new level of desperation and frustration among the Islamic State’s remaining adherents.

The group views Sufi Muslims as apostates and has attacked Sufi shrines in northern Africa and Iraq. But the Islamic State has generally not targeted Sufis in Egypt, where the strain of Sunni Islam has deep roots that date back centuries and broad popular appeal.

“As you get more desperate, you also get internal feuding over who is more puritanical,” said Bernard Haykel, a professor at Princeton University who has studied the Islamic State’s religious roots. “Everyone is trying to compete to show they are truer to the cause. They want to cast themselves as the hardest of the hard-liners.”

Until recently, Islamic State militants in Egypt had made an effort to appeal to disaffected Islamists who had supported the Muslim Brotherhood or opposed Egyptian President Abdel Fatah al-Sissi’s tight grip on power. The al-Rawda mosque attack suggested that the group was almost entirely focused on amassing body counts rather than holding territory or winning new followers.

“On its face, it’s a really dumb thing to do,” Haykel said. “What do you stand to gain other than the hatred and contempt of Muslims all over the world?”

One purpose of the attack may have been to demonstrate that the Islamic State, despite the collapse of its armies in Iraq and Syria, remains deadly and relevant. "One way to do that is by turning to increasingly brutal and savage terrorist attacks," said Shadi Hamid, the author of "Islamic Exceptionalism" and a senior fellow at the Brookings Institution.

U.S. officials have been carefully monitoring some of the more significant affiliates in recent weeks to see how they might be affected by the fall of the core group’s capital in Raqqa, Syria. One concern is the possibility that substantial numbers of Islamic State fighters — including perhaps the senior leadership — could resurface in a new location. Officials also are worried that one of the regional affiliates may seek to launch a major attack against Western targets as an act of revenge for the deaths of comrades in Iraq and Syria.

“We say that the Islamic State has been defeated, but only as a military force,” said a senior U.S. counterterrorism official who spoke on the condition of anonymity to discuss security assessments. “Homegrown insurgencies are going to go on for a while and will be harder to defeat. The hope is that we can get to the point where local forces can contain the threat on their own, without support from the international coalition or U.S. advisers.”

The U.S. military has been largely successful in preventing a second Islamic State caliphate from taking hold in Libya. But last month, Gen. Joseph F. Dunford Jr., chairman of the Joint Chiefs of Staff, told reporters that other affiliates remain worrisome, including “an ISIS concentration in Sinai that Egypt has been working on” for some time.

There has been little evidence in recent months that the core organization is providing money or logistical support to its regional affiliates, but the group’s ideology and brutal tactics remain a common bond, the officials said.

“What ISIS is absolutely trying to do is leverage local insurgencies now to rebrand themselves,” Dunford said. “They are trying to maintain relevance.”

The Sinai chapter presents an exceptionally difficult challenge, because of the group’s growing capabilities and Egypt’s seeming inability to contain them — or to even acknowledge the seriousness of the threat, U.S. counterterrorism officials said.

Friday’s mosque attack occurred in northern Sinai, in Bir al-Abd, a town in a coastal area noted for its heavy security presence. The assailants’ ability to inflict a savage blow in such a place suggested to some current and former U.S. officials that the momentum lies with the terrorists, despite a two-year campaign by the Sissi government to destroy the group.

“For whatever reason, the Egyptians have not worked closely with us in the northern Sinai,” said Stuart Jones, a former deputy chief of mission at the U.S. Embassy in Cairo and vice president at the Cohen Group. “This just shows that the Egyptians need our help with training and the special kinds of equipment it takes to defeat insurgencies.”

He envisions a program similar to the one U.S. troops have been executing in Iraq.

In the wake of the attack, President Trump suggested that more American help might be on the way. “The world cannot tolerate terrorism, we must defeat them militarily and discredit the extremist ideology that forms the basis of their existence!” he tweeted. “We have to get TOUGHER AND SMARTER than ever before.”

But it was unclear exactly what kind of program the president wants to see. His tweet went on to call for the construction of a border wall and an immigration ban.

In Egypt, Sissi’s approach has been to launch a broad campaign against all Islamist groups, including Egypt’s Muslim Brotherhood, which has renounced violence in recent years. The net effect has been to drive even moderate Islamists to support the extremists. Friday’s attack is likely to lead Sissi, with Trump’s support, to get even tougher.

James Jeffrey, a former ambassador to Iraq and senior fellow at the Washington Institute, said the attack “will serve as an argument for Sissi to continue his draconian crackdown and authoritarian rule.”