The gunmen opened fire and also threw grenades in the upmarket Westgate shopping centre, sending scores fleeing into shops, a cinema and onto the streets in search of safety.
Shooting continued for several hours after the initial assault as troops surrounded the mall and police and soldiers combed the building, hunting down the attackers shop by shop.
A police officer inside the building said the gunmen were barricaded inside a branch of the Nakumatt supermarket, one of Kenya's biggest chains.
"We got three bodies from this shop," he said, standing a dozen metres from the supermarket entrance and pointing to a children's shoe shop, where blood lay in pools. He turned to a nearby hamburger bar, where music still played and food lay abandoned in a similar bloody scene, and added: "And a couple of bodies here."
The Westgate mall attack was the single biggest since al-Qaeda's east Africa cell bombed the US embassy in Nairobi in 1998, killing more than 200 people. In 2002, the same militant cell attacked an Israeli-owned hotel and tried to shoot down an Israeli jet in a co-ordinated attack.
At one point yesterday, plainclothes policemen lay on the floor with guns trained on the supermarket entrance. Tiles were smeared with blood, bullet casings were strewn on the floor and windows were shattered. A policeman dragged the corpse of a girl across the floor and laid her on a stretcher.
Local television stations reported hostages had been taken, but there was no official confirmation. Other reports said Kenyan forces had the gunmen "pinned down".
The Somali militant group al-Shabaab - which Kenya blames for a string of shootings, bombings and grenade attacks against churches and the security forces - claimed responsibility for the attack late yesterday. It had previously threatened to strike the Westgate mall, popular with the city's expatriate community.
Rob Vandijk, who works at the Dutch embassy, said he was eating at a restaurant in the shopping centre when attackers threw hand grenades inside the building. He said gunfire then rang out and people screamed.
One survivor, a former British soldier said: "I personally touched the eyes of four people and they were dead. One of them was a child. It's carnage up there."
Manish Turohit, 18, said he saw gunmen with AK-47s and vests with hand grenades on them inside the centre. He escaped after hiding in the car park for two hours.
One witness to the attack claimed the gunmen told Muslims to stand up and leave and that non-Muslims would be targeted. And a woman leaving the building told a journalist that one of the attackers had told all Muslims to leave the premises.
"They don't seem like thugs, this is not a robbery incident," said Yukeh Mannasseh who was on the mall's top floor when the shooting started. "It seems like an attack. The guards who saw them said they were shooting indiscriminately."
A spokesman for Kenya's Interior Ministry said: "It is a possibility that it is an attack by terrorists, so we are treating the matter very seriously."
Asked if foreign security services were involved in the operation to flush out the attackers, he said: "At this stage it has not become necessary yet."
Some shoppers ran up stairs and escalators and hid around the mall's cinema complex. Police found another terrified group hiding in a toilet on the first floor.
At least two dozen wounded were wheeled out on stretchers and in shopping trolleys. Many of the victims had been injured by flying debris. Others walked out, some with bloodied clothing wrapped around wounds.
"The casualties are many, and that's only what we have on the outside," Kenya Red Cross Society secretary general Abbas Guled said. "Inside there are even more casualties."
Al-Shabaab has previously threatened to attack Nairobi's tower blocks and "soft" targets including nightclubs and hotels in the capital known to be popular with Westerners. This, say the militants, is in retaliation for Kenya sending troops into Somalia to fight them.
A suspected al-Shabaab attack in January left five people dead and three injured at a restaurant in the eastern city of Garissa.