‘‘The perpetrators of this heinous act must be brought to justice, and we have offered our full support to the Kenyan Government to do so,’’ Caitlin Hayden, a spokeswoman for the White House National Security Council, said in the statement.
The U.S. embassy in Nairobi said it was in contact with local authorities and offered assistance. Some British security personnel assisted in the response.
The gunmen told hostages that non-Muslims would be targeted, said Elijah Kamau, who was at the mall at the time of the midday attack.
‘‘The gunmen told Muslims to stand up and leave. They were safe, and non-Muslims would be targeted,’’ he said.
Jay Patel, who sought cover on an upper floor in the mall when shooting began, said that when he looked out of a window onto the upper parking deck of the mall he saw the gunmen with a group of people. Patel said that as the attackers were talking, some of the people stood up and left and the others were shot.
The attack was carried out by terrorists, said police chief Benson Kibue. He did not specify a group. He said it was likely that no more than 10 attackers were involved.
Somalia’s president — the leader of a neighboring country familiar with terrorist attacks — said his nation knows ‘‘only too well the human costs of violence like this’’ as he extended prayers to those in Kenya.
‘‘These heartless acts against defenseless civilians, including innocent children, are beyond the pale and cannot be tolerated. We stand shoulder to shoulder with Kenya in its time of grief for these lives lost and the many injured,’’ President Hassan Sheikh Mohamud said.
The gunmen carried AK-47s and wore vests with hand grenades on them, said Manish Turohit, 18, who hid in a parking garage for two hours.
‘‘They just came in and threw a grenade. We were running and they opened fire. They were shouting and firing,’’ he said after marching out of the mall in a line of 15 people who all held their hands in the air.
Dozens of people were wounded. A local hospital was overwhelmed with the number of wounded being brought in hours after the attack and diverted them to a second facility. Officials said Kenyans turned out in droves to donate blood.
The United Nations secretary-general’s office said that Ban Ki-moon has spoken with President Uhuru Kenyatta and expressed his concern. British Prime Minister David Cameron also called Kenyatta and offered assistance.
Kenyan authorities said they have thwarted other large-scale attacks targeting public spaces. Kenyan police said in September 2012 they disrupted a major terrorist attack in its final stages of planning, arresting two people with explosive devices and a cache of weapons and ammunition.
Anti-terror Police Unit boss Boniface Mwaniki said vests found were similar to those used in attacks that killed 76 people in Uganda who gathered to watch the soccer World Cup finals on TV in July 2010. Al-Shabab claimed responsibility for those bombings, saying the attack was in retaliation for Uganda’s participation in the African Union’s peacekeeping mission in Somalia.
Associated Press reporter Douglass K. Daniel in Washington contributed to this report.