Nairobi, Kenya - When she heard the first crackle of shots, Fiona Herbert thought she was listening to fireworks, rather than the bullets that signalled the start of a bloody siege on an upmarket shopping mall here in Kenya's capital.

The 34-year-old Briton, who lives in Kenya, described chaotic scenes as she grabbed her baby son and darted out of the ground-floor cafe, fleeing with other shoppers into a furniture shop, jamming a chair behind the door and ducking into a store room.

Outside, around a dozen masked attackers tossed grenades and shot shoppers in the head, using pistols and assault rifles, ostensibly to advance the cause of al-Shabaab, an armed Somali outfit with links to al-Qaeda and ambitions to topple their country's UN-backed government.

"Everyone was texting and tweeting on their phones," Herbert told Al Jazeera. "News reports were saying that police have it under control - but it didn't feel like that to us. We could hear gunshots and shouting. I wasn't going anywhere."

Hiding in an unlit cupboard, Herbert and others softly keyed text messages to loved ones. Amid reports that gunmen were singling out non-Muslims, some even tried to memorise Quranic prayers in order to pass themselves off as adherents.

"There was no way I could learn an Arabic phrase and get away with being Muslim," said Herbert, a child psychologist. "I'm ginger-haired and I've got a ginger baby. If they'd got into the shop then we were both dead."

Under siege

Kenyan police and commandos circled the mall and launched counter-offensives against the gunmen on different floors of the Westgate Shopping Mall, which houses 80 stores, restaurants and a cinema that caters for wealthy Kenyans, expatriates and tourists alike.

Camouflage-wearing troops circled the five-storey block, exchanging fire with gunmen and rescuing civilians. After six hours, Herbert scarpered through the blood-splattered and smoke-filled atrium to safety. Some escaped by jumping from balconies to lower floors. One person fled the mall while pushing an injured victim out in a shopping trolley.

On Sunday, gunmen remained inside the mall with hostages. After a 30-hour siege, officials counted 59 dead victims and 175 injured. More than 1,000 people had escaped and it was unclear how many others were held hostage or were hiding.

The victims were men and women of all ages. They included Kenyans, three Britons, two from France and two diplomats - one from Canada and another from Ghana, and a nephew of Kenya's president, Uhuru Kenyatta, who denounced the attackers for their "philosophy of cowardice".

"This is not Kenya's war. This is an international war," added Kenyatta, who himself faces a trial at the International Criminal Court in November. He vowed to defeat the attackers, rescue the hostages and hunt down and punish the masterminds.

An Israeli security source said that Israeli advisers were at the scene, helping Kenya to work out how to end the siege.

(Anti) social media?

As al-Shabaab's foot soldiers held the building, the hard-line Islamist group used the social networking site Twitter to claim responsibility for the attack, and to ridicule Kenya's military for letting down its guard in a city of some three million people.

Those inside were "still fighting and still strong", the group tweeted. "What Kenyans are witnessing at #Westgate is retributive justice for crimes committed by their military, albeit largely miniscule in nature," it added.

It is the latest retaliation since Kenya sent troops into southern Somalia in 2011 to battle al-Shabaab. The group and its allies stand accused of dozens of attacks on churches, mosques and minibuses in Eastleigh, a Somali-dominated district of Nairobi, and towns and refugee camps near the Somali border.

"Everybody knew this was coming," said Cedric Barnes, an analyst at the International Crisis Group. "It demonstrates that al-Shabaab is an active threat against these targets. We know that many other plots have been disrupted over the past two years - this is the one that got through."

The assault was the biggest single attack in Kenya since al-Qaeda's East Africa cell bombed the US embassy in Nairobi in 1998, killing more than 200 people. In 2002, the same unit attacked an Israeli-owned hotel on the coast and tried to shoot down an Israeli jet in coordinated attacks.

'They are losing the war'

Kenyan troops in Somalia are part of a 17,700-strong African Union force that seeks to quash al-Shabaab, bolster a fledgling government in Mogadishu and restore stability to a country that has seen little but war and chaos for more than two decades.

Nairobi got involved after tourists were seized from a Kenyan resort island close to the Somali border. In September 2012, Kenyan forces ousted al-Shabaab from its stronghold in Kismayu, a southern Somali port where the group earned millions by taxing charcoal exports.

"Al-Shabaab is a small minority group with limited support across Somalia," said Ali Nur, the ambassador for the Somali government in Mogadishu. "They are on the run and they are losing the war. This attack is their way of saying they are still there."

While al-Shabaab has suffered battlefield setbacks, analysts say al-Qaeda know-how has helped the outfit develop guerrilla tactics. The group regularly launch attacks in Mogadishu and other parts of battle-scarred Somalia.

In July 2010, the rebels staged a bomb attack in Ugandan capital Kampala, killing 79 people who were watching the soccer World Cup final. The strike, its first on foreign soil, was purportedly to avenge Uganda's participation in the African peacekeeping force.

Innocents remain trapped

"Clearly al-Shabaab has demonstrated the ability to carry out a complex attack outside its theatre of operations," said Abdi Aynte, of The Heritage Institute for Policy Studies think-tank, and a former Al Jazeera Online journalist. "The group has honed its capacity to wage asymmetric warfare, even as its conventional ability has weakened."

The raid showed "a major failure on the part of the Kenyan security services", which had not detected an operation that must have involved several weeks of planning and at least a dozen agents. "That they didn't detect it raises questions about their capacity," he said.

On Sunday evening, Herbert was settled back at home with her nine-month-old son, tracking the final stages of the siege, as commandoes circled the building containing between 10-15 attackers, which reportedly include both men and women.

Her thoughts were with the innocents still trapped inside the mall, condemning the atackers.

"What they are doing is preposterous and pure terrorism," she said. "They were asking questions about the Quran. Even if people were Muslim, they could still get the wrong answer and be killed. Saying you were Muslim was not foolproof, it was just desperate people, grasping at straws."

Follow James Reinl on Twitter: @jamesreinl