NAIROBI, Kenya — Kenyan security forces swept into an upscale shopping mall late Sunday to try to end a two-day standoff with heavily armed Islamist militants after a gruesome attack that reflected the surprising resiliency of one of Africa’s most brutal insurgent groups.
Authorities later said most hostages had been freed, but they provided few details. It appeared that at least some members of Somalia’s Al Shabab militia, which asserted responsibility for the attack, were still holed up early Monday in the Westgate Premier Shopping Mall, where they killed 68 people in the deadliest terrorist attack in Kenya in 15 years.
‘‘Most of the hostages have been released, and the Kenya Defense Forces has taken control of most parts of the building,’’ a Kenyan military spokesman, Colonel Cyrus Oguna, told the television station KTN, according to Reuters. He did not say how many hostages had been held or freed.
Local news reports described several explosions late Sunday emanating from the mall, which has been cordoned off.
In a nationally televised news conference, Kenyan President Uhuru Kenyatta declared that the siege would probably end soon.
‘‘The criminals are now located in one place within the building. With the professionals on site, I assure Kenyans that we have as good a chance to successfully neutralize the terrorists as we can hope for,’’ he said. Kenyatta added that one of his nephews and his fiancee were among those killed.
The attack stunned Kenya, which has one of the continent’s biggest economies and has been a major hub for US military and humanitarian activity in East Africa.
For the past two years, Al Shabab, which is linked to Al Qaeda, has been considered by many US officials and analysts to be all but defeated. The militia had lost much of the territory it once held in Somalia, including the capital, Mogadishu. It was pushed to the margins by a campaign that has involved US Special Operations troops as well as African forces mobilized largely by Kenya, Uganda, Ethiopia, and Burundi.
But the well-organized assault on the mall that began around lunchtime Saturday upended the calculations of Kenyan and Western security officials. As of early Monday, the toll had risen to 68 dead and more than 175 injured, the Kenyan Red Cross said.
The attackers, who carried grenades and clutched machine guns and AK-47 assault rifles, had chosen a target popular with Westerners and wealthy Kenyans, a move sure to hurt the nation’s critical tourism industry and spread unease among the numerous Western aid agencies based in Nairobi.
‘‘This tells me that Al Shabab remains resilient, able and willing to strike beyond Somalia’s borders to survive,’’ said Juan Zarate, who served as a senior counterterrorism adviser in the administration of President George W. Bush. ‘‘They remain a real terrorist threat to Somalia, the region, and potentially beyond.’’
The dead included numerous foreigners from Britain, France, Canada, Australia, and other countries. While no Americans were reported killed, Ruhila Adatia-Sood, the wife of Ketan Sood, a Foreign Service national working for the US Agency for International Development in Nairobi, was among the dead, USAID said in a statement. Five American citizens were wounded, officials said.
In numerous tweets from a Twitter handle that was later disabled, Al Shabab declared that the attack was in revenge for Kenya sending its troops to fight in neighboring Somalia and said the group was shifting the battleground to Kenya.
At Nairobi’s Aga Khan Hospital on Sunday, survivors spoke about how they escaped death in the mall. One British man said his wife and children were hiding behind a meat counter in a store with other women and children. The gunmen sprayed bullets at them, killing a woman and a teenage girl, and wounding his wife, said the man, who asked that neither his nor his spouse’s name be used because they feared retribution.
The gunmen, the man said, released the children who were still alive and informed his injured wife that she, too, could leave if she converted to Islam, making her recite the Shahada, Islam’s profession of belief.
Then the gunmen handed chocolates to the children as they left the mall, the man said.
The assault was the deadliest in Kenya since Al Qaeda operatives masterminded the twin bombings of the US embassies in Nairobi and Dar es Salaam, Tanzania, in 1998. Al Shabab also staged the twin bombings in Kampala, Uganda, during the World Cup in July 2010, killing more than 70 people.
That attack, the militia said, was in retaliation for Uganda sending its troops to Somalia.
But since mid-2011, Al Shabab has been on its heels, following an offensive by African Union forces backed by the United States and Western governments. While it controls large swaths of southern Somalia’s countryside, the militia has been riven by a struggle among its core leadership.
In Kenya, the militia has staged small attacks on local targets such as bus stations and churches, killing a handful of people, since the government sent troops to Somalia in October 2011. But Saturday’s attack suggested far greater operational planning and tactical sophistication, analysts said.
‘‘The attack is more likely to be a first salvo of a reinvigorated Al Shabab than the last gasp of a defeated organization,’’ said Peter Pham, head of the Africa Center at the Atlantic Council. ‘‘While there have been divisions within and defections from Al Shabab, my sense is that the hard-core element will actually emerge more nimble and lethal as a result of shedding those elements.’’
The attack on the mall, he said, would have required a local unit to conduct reconnaissance and plan other details, suggesting that the militia has an ‘‘extensive support network’’ in Kenya. There are thousands of Somalis living in Nairobi and other parts of Kenya, as well as extremists within the local Muslim community.
Al Shabab is believed to have a strong fund-raising network here. Targeting the mall, Pham said, sends a ‘‘much clearer signal of the group’s resurgence, both to Al Qaeda central and other regional affiliates and to audiences from which it will now, undoubtedly, try to recruit.’’