NAIROBI, Kenya — Kenyan security forces swept into an upscale Nairobi mall late Sunday night in an effort to end a two-day standoff with heavily armed assailants that left 68 dead, and most of the hostages were rescued, according to officials.

Al-Shabab, the Somali militia linked to al-Qaida, claimed responsibility for the attack, the deadliest in Kenya since the 1998 U.S. Embassy bombings. Another 175 people were injured, while up to 30 people had been held hostage.

“Most of the hostages have been released, and the Kenya Defence Forces has taken control of most parts of the building,” Kenyan military spokesman Colonel Cyrus Oguna told the television station KTN, according to Reuters. He did say how many hostages had been held or freed.

Terrorism experts said the assault showed surprising levels of operational planning and tactical sophistication for a militant group that had been riven by infighting and had lost much of the territory it once held in Somalia.

“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 Atlantic Council’s Michael S. Ansari Africa Center. “While there have been divisions within and defections from al-Shabab, my sense is that the hardcore element will actually emerge more nimble and lethal as a result of shedding those elements.”

The attackers, strapped with grenades and wielding machine guns and AK-47 rifles, had launched their attack on the Westgate Premier Shopping Mall on Saturday. An unknown number of people had remained inside the building, hiding from the gunmen. Sporadic gunfire erupted at the mall earlier Sunday as additional Kenyan security forces arrived to help defuse the crisis.

In a tweet on Sunday night, Kenya’s National Disaster Operations Center said, “Major security assault by security forces ongoing to end two-day siege at Westgate mall.” In another tweet, the center said, “this will end tonight. Our forces will prevail.”

And al-Shabab in two tweets said: “Kenyan forces who’ve just attempted a roof landing must know that they are jeopardising the lives of all the hostages at #Westgate. “The Kenyan government shall be held responsible for any loss of life as a result of such an imprudent move. The call is yours!”

Still, it was unclear whether the operation was an all-out effort to retake the mall or whether it amounted to another rescue operation to retrieve people trapped inside. Local news reports described several explosions coming from the mall, which has been cordoned off from the media and onlookers.

In an earlier statement, Kenya’s Red Cross said that 68 people had been killed and 49 people had been reported missing, but it was unclear whether this number included the hostages. A senior Kenyan Interior Ministry official, Joseph Ole Lenku, said that Kenyan forces had rescued about 1,000 people from the mall and that 10 to 15 attackers remained inside the shopping center.

“The government will go out of its way to make sure we do not lose lives,” Lenku told reporters.

In a nationally televised news conference, Kenyan President Uhuru Kenyatta declared that the siege had a good chance of ending and urged the nation to be patient. “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 fiance were among those killed in the attack.

Former Kenyan Prime Minister Raila Odinga told reporters earlier Sunday that he had been told that the precise number of hostages inside the mall was unknown.

Earlier Sunday, Al-Shabab asserted responsibility for the assault in numerous tweets using its official Twitter handle, @HSM_Press. The militia said it was retaliating for Kenya sending troops to fight in neighboring Somalia, where it remains a key military actor. “For long we have waged war against the Kenyans in our land, now it’s time to shift the battleground and take the war to their land,” the militia said in one tweet.

Early Sunday morning, al-Shabab’s Twitter account was suspended for the third time this year. Within hours, the militia had launched another Twitter handle_ HSM_PressOffice — and began to tweet again. On Sunday evening, the militia said it had made contact again with the “Westgate warriors” and said that an attempt by Kenyan security forces to storm the building “failed miserably.”

“More than 30 hours have now passed and, like rabbits caught in the headlights, Kenyans are still shell-shocked,” the militia said in another tweet.

The dead and injured included young and old, Kenyans and foreigners, according to witnesses and a U.S. State Department official familiar with the situation, who spoke on the condition of anonymity because the official was not authorized to speak publicly. No Americans were believed to be among the dead, the official said. Three U.S. citizens were reported injured.

Several children were reported killed or injured.

Annamaria Watrin, an American aid worker from Minnesota, said a friend and his 13-year-old daughter had gone to the mall for a birthday party. “As they went to park their car, she saw five gunmen pop out. They shot her dad. He died,” Watrin said. The girl was injured. Watrin said the girl spent a couple of hours huddled in the car before Kenyan security agents could evacuate her in an ambulance.

The assault was the deadliest terrorist attack in this East Africa nation since al-Qaida operatives staged twin bombings of the U.S. embassies in Nairobi and Dar es Salaam, Tanzania, in 1998, killing more than 200 people in Kenya alone. Al-Shabab has staged numerous smaller attacks in the country since the government sent troops to Somalia in October 2011 to fight the militia. Most of those assaults targeted bus stations and churches, but never areas frequented by Westerners and wealthy Kenyans. The tourism industry is Kenya’s second-largest source of foreign exchange, and dozens of Western aid agencies and businesses are based in the country.

Now, Saturday’s attack has appeared to usher in a new war on its soil for Kenya, long a bulwark of stability in the region and a key U.S. ally in the fight against terrorism.

The militia also orchestrated 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 the participation of Ugandan soldiers in an African force sent to protect Somalia’s government.

Kenyatta vowed to hunt down the perpetrators.

“We have overcome terrorist attacks before. We will defeat them again,” Kenyatta said, adding that some of his close relatives were among the dead.

The scene at the mall Saturday afternoon was chaotic.

“We have taken so many to the hospital,” said Zulekha Khalid, a Kenyan Red Cross worker taking cover behind a police truck as a barrage of bullets was fired from the direction of the mall.

The presidential office said in a tweet that a wounded attacker had been taken into custody and was hospitalized but died of his injuries.

Some witnesses and security officials said the assailants, dressed in dark clothes, numbered no more than five, while others said there were as many 10 or 15. Witnesses said one was a woman who wore a hijab, attire favored by conservative Muslim women.

According to several accounts, including one relayed to a Washington Post reporter, the attackers had ordered Muslims to leave the premises in an apparent attempt to target non-Muslims.

By early evening, the attackers were on an upper floor of the mall, holding hostages, according to police officials and security officers at the scene. Scores of people remained inside, huddling in stores, banks, even closets. Outside, their relatives frantically sent them text messages, comforting them as best as they could.

Earlier, many had filtered out with the help of security personnel, their faces revealing the anguish of their ordeal. Some collapsed on the asphalt, while others had to be carried out, covered in blood from bullet wounds. Ambulances waited outside to ferry the wounded to hospitals.

Outside the mall entrance, two bodies lay on the ground, next to cars peppered with bullet holes.

Elizabeth Muthona, an employee of Nakumatt, a supermarket inside the mall, watched solemnly Saturday afternoon as more people fled the area, some with bleeding wounds, some carrying their kids in their arms. She, too, had fled moments earlier.

For several hours, she hid inside a cardboard box, holding her breath as gunmen walked through the store. “I heard the gunshots, and we started running into the store, and we hid in a carton box,” said Muthona, in a quiet and shaking voice. “The gunmen came inside the store, but they didn’t find us.” She paused, then added, “I didn’t expect this to happen. There was so much security inside the mall.”

Frank Musungu, an army warrant officer who was shopping in the mall, said he and another security officer tried to assist someone. But the person was one of the assailants. “He stood up and shot my friend,” recalled Musungu, who took cover behind a wall. “I pulled him towards me and carried him to an ambulance.” Musungu said one attacker wore a white turban, but others wore civilian clothes, “dressed like me and you.”

In Washington, Secretary of State John Kerry issued a statement saying that the attack was “a heartbreaking reminder that there exists unspeakable evil in our world which can destroy life in a senseless instant.” His statement said that the wife of a U.S. Agency for International Development worker was among those killed.

Many middle-class Kenyans and expatriates have long voiced concern about a possible attack on Westgate and other upscale shopping centers and restaurants in Nairobi. Guards at the malls check vehicles for explosives and use hand-held metal scans on shoppers, but they are mostly unarmed, incapable of responding to a heavily armed attack.

Al-Shabab said in tweets that “what Kenyans are witnessing at Westgate is retributive justice for crimes committed by their military.”

The militia said it was in contact with the assailants inside the mall and ruled out negotiations for the release of the hostages.

Only subscribers are eligible to post comments. Please subscribe or to participate in the conversation. Here’s why.

Use the form below to reset your password. When you've submitted your account email, we will send an email with a reset code.