have arrested one of the gunmen who attacked a shopping mall in the capital, killing at least 39 people, on Saturday, the Kenyan Presidency said on Twitter.
In a separate tweet, the east African country's head of police, David Kimaiyo, said several other assailants had been pinned down after soldiers and police moved into the mall to hunt down the attackers.
Kenyan President Uhuru Kenyatta said he himself had lost close relatives in Saturday's mass shooting in a Nairobi shopping mall.
Addressing the relatives of victims, a sombre Kenyatta said in an address to the nation: "I ask God to give you comfort as you confront this tragedy, and I know what you feel, having also lost very close family members in this attack."
Somalia's al Qaeda-linked Shabab rebels on Saturday claimed resposibility for the attack on the mall, saying on Twitter it was in retaliation for Kenya's military intervention in Somalia.
"The Mujahideen entered #Westgate Mall today (Saturday) at around noon and are still inside the mall, fighting the #Kenyan Kuffar inside their own turf," the group said on Twitter.
The gunmen were "pinned down" after hours of painstaking evacuations, with police going shop to shop to secure the Westgate shopping mall, a security source told AFP.
"The attackers have been isolated and are pinned down in an area on one of the floors. The rest of the mall seems to be secure," a security source told AFP at the scene.
Read more: Somalia's Shebab claims responsibility for Nairobi mall attack
An unknown number of hostages are still being held by Islamist gunmen.
"Hostage numbers still unknown, but they are in several locations. No communication as yet. Upper levels (of the mall) have been secured," the government's National Disaster Operation Centre said in a situation update posted on Twitter.
Senior police sources said they believed a well-organised "terror gang" numbering around 10 was behind the assault on the shopping centre, which was packed with around 1,000 shoppers when it was besieged at midday.
A mother and her children hide from gunmen at Westgate Shopping Centre in Nairobi. Reuters photo
An eyewitness told AFP that he heard the gunmen speaking Arabic or Somali and saw the group executing shoppers, in what appeared to be the worst attack in Nairobi since an al Qaeda bombing at the US embassy killed more than 200 in 1998.
"The death toll is now standing at 30. This includes those who have died at the scene and at the hospital," a senior police official told reporters. The Red Cross confirmed the figure and said another 60 had been wounded in the attack.
Read more: Shabab Twitter account suspended after Kenya mall attack claims
The Kenyan government, which has troops battling Islamist Shebab insurgents in neighbouring Somalia, said it was too early to say who was responsible.
"Investigations have begun to find out the perpetrators of this crime. I urge Kenyans not to speculate," interior minister Joseph Ole Lenku said in a statement.
An armed police officer takes cover during a bout of gunfire outside the Westgate Mall in Nairobi. AP photo
Police at the scene said a suspect wounded in the firefight had been detained and taken to hospital under armed guard.
“We are treating this as a terror attack,” said police chief Benson Kibue, adding that there were most likely 10 attackers involved.
"They appeared to be wearing a similar outfit, and others covered their faces," a police official said. "The pattern of the attack and the way they were speaking to their targets clearly point to a well-planned attack by a terror gang."
Earlier a police source said it had been confirmed that the attackers were holding at least seven hostages. As darkness fell over Nairobi, their fate was unclear.
A Kenyan army soldier keeps guard in an armoured carrier vehicle at the Westgate Shopping Centre. Reuters photo
Kenyan troops could be seen moving around and inside the shopping centre while special forces had joined the operation.
An AFP reporter said she saw at least 20 people rescued from a toy shop. Dozens of wounded, some of them bleeding children, were taken away from the mall on stretchers.
The President called the security operation under way "delicate" and said a top priority was to safeguard hostages.
As the attack unfolded shortly after noon Saturday, the al-Qaida-linked gunmen asked the victims they had cornered if they were Muslim: If the answer was yes, several witnesses said, those people were free to go. The non-Muslims were not.
Video: Gunmen attack Nairobi shopping mall
'I saw people being executed'
A shop manager who managed to escape said at one point "it seemed that the shooters had taken control of all the mall".
"They spoke something that seemed like Arabic or Somali," said a man who escaped the mall and gave his name only as Jay. "I saw people being executed after being asked to say something."
Shocked people -- black, white and Indian -- could be seen running away from the Westgate centre clutching children while others crawled along walls to avoid stray bullets.
Kenneth Kerich, who was shopping when the attack happened, described scenes of panic.
Civilians escape an area at the Westgate Shopping Centre in Nairobi. Reuters photo
"I suddenly heard gunshots and saw everyone running around so we lied down. I saw two people who were lying down and bleeding, I think they were hit by bullets," he said.
"Initially we thought it is police fighting thugs. But we could not leave until when officers walked in, shot in the air and told us to get out."
An eyewitness who survived the assault by gunmen said he saw the body of a child being wheeled out of the mall.
"The gunmen tried to fire at my head but missed. At least 50 people were shot. There are definitely many casualties," mall employee Sudjar Singh told AFP.
"I saw a young boy carried out on a shopping cart, it looked like he was about 5 or 6. It looked like he was gone, he was not moving or making any noise."
Vehicles riddled with bullet holes were left abandoned in front of the mall as the Red Cross appealed for blood donations and police instructed residents of the Westlands neighbourhood to stay away.
A Red Cross assistant helps a child outside the Westgate Mall in Nairobi. AP photo
'Senseless act of violence'
Americans were reportedly among those injured, the United States said as it condemned the "senseless act of violence".
"We have reports of American citizens injured in the attack, and the US embassy is actively reaching out to provide assistance," state department spokeswoman Marie Harf said without elaborating, citing privacy concerns.
The four-storey mall, which has several Israeli-owned businesses, is a hub for Nairobi-based Westerners and one of the foremost symbols of Kenya's affluent classes. It has long been considered a potential terror target. It opened in 2007 and has restaurants, cafes, banks, a large supermarket and a cinema.
It is popular with the large expatriate community living in the residential neighbourhoods around it, including with foreign staff from the United Nations, which has its third largest global centre nearby.
Security agencies have regularly included the Westgate shopping centre on lists of sites they feared could be targeted by al Qaeda-linked groups.
The mother and a security guard help a child outside the Westgate Mall in Nairobi. AP photo
The Somali insurgents from the Shebab group have repeatedly threatened to strike at the heart of Kenya in retaliation for Nairobi's military involvement alongside the government they are trying to overthrow.
UN Secretary-General Ban Ki-moon is following the attack "closely and with alarm", a statement from his office said.
British foreign secretary William Hague said on Twitter that his country was "in close touch with Kenyan authorities about the attack in Nairobi. Our urgent priority is the welfare of UK nationals."