* Somali Islamists linked to al Qaeda claim attack
* Group wants withdrawal of Kenyan troops from Somalia
* President loses relatives in raid, vows punishment
* Volleys of gunfire, helicopters swoop low over mall
By Richard Lough and Edmund Blair
NAIROBI, Sept 22 (Reuters) - Islamist militants were holding hostages on Sunday at a shopping mall in Nairobi, where at least 59 people were killed in an attack by the Somali al Shabaab group, which demanded Kenya pull troops back across the border.
Brief volleys of gunfire and a blast interrupted hours of stalemate. A Reuters correspondent saw security personnel on the move and, as dusk closed, in two helicopters swooped low over the Westgate shopping centre, which has several Israeli-owned outlets and is frequented by prosperous Kenyans and foreigners.
Mobile phone signals began to fail in the area as darkness fell. Kenya's president, vowing to stand firm against Somali militants, was cautious about the outcome, saying chances of the siege ending well were "as good ... as we can hope for".
"We will punish the masterminds swiftly and painfully," he added, saying 59 people had been killed and more than 175 taken to hospitals. Previous such raids, in Russia, the 2008 Mumbai attacks or January's al Qaeda assault on an Algerian gas plant, have generally ended only with many hostages losing their lives.
British Prime Minister David Cameron, confirming three Britons were dead, said: "We should prepare ourselves for further bad news."
U.S. President Barack Obama called Kenyan President Uhuru Kenyatta on Sunday to express condolences over what the White House called a "terrorist attack" by al Shabaab, and offered support to bring the perpetrators to justice.
Other foreigners, including a French mother and daughter and two diplomats from Canada and Ghana, were killed in Saturday's attack, which was claimed by al Shabaab.
Shortly after the shots were fired, troops in camouflage ran crouching below a restaurant terrace along the front of the building that had been buzzing with customers when assailants charged in.
For hours after the brazen attack, the dead were strewn around tables of unfinished meals. At one burger restaurant, a man and woman lay in a final embrace, before their bodies were removed.
Scores of Kenyans gathered on Sunday at a site overlooking the mall, awaiting what they expected to be a violent denouement. "They entered through blood, that's how they'll leave," said Jonathan Maungo, a private security guard.
President Kenyatta, facing his first major security challenge since being elected in March, said he lost a nephew and his fiancée in the raid and vowed to defeat the militants.
In an address, he urged wealthy governments not to warn their citizens against visiting a country heavily dependent on tourist income, while insisting he would not pull out Kenyan troops from Somalia: "We shall not relent on the war on terror."
Saying all the gunmen were now in one place, Kenyatta added: "With the professionals on site, I assure Kenyans that we have as good a chance to successfully neutralise the terrorists as we can hope for." Foreign governments including Israel offered help.
But the heavily armed and well disciplined attackers, still unidentified, had shown no hesitation in killing civilians.
The spokesman for Al Shabaab's military operations told Reuters in Somalia his group had nothing to fear: "Where will Uhuru Kenyatta get the power with which he threatened us?" said Sheikh Abdiasis Abu Musab.
The assault was the biggest single attack in Kenya since al Qaeda's East Africa cell bombed the U.S. Embassy in Nairobi in 1998, killing more than 200 people.
Al Shabaab's siege underlined its ability to cause major disruptions with relatively limited resources.
"In terms of capacity, while the group has grown considerably weaker in terms of being able to wage a conventional war, it is now ever more capable of carrying out asymmetric warfare," said Abdi Aynte, director of Mogadishu's Heritage Institute of Policy Studies.
The focus of attention on Sunday was on the mall's branch of the Nakumatt supermarket, one of Kenya's biggest chains. The company closed its other stores on Sunday for security reasons.
Kenyatta, who said Kenya was still trying to establish conclusively who was responsible, said women were among the 10 to 15 attackers. Asked whether hostages had explosives strapped to them, he said he would not comment on operational issues.
Aynte also said the raid showed "a major failure on the part of the Kenyan security services", which had not detected an operation that must have taken several months to plan. Other experts said Western agencies had also not picked it up.
Kenya's deputy president, William Ruto, asked judges at the International Criminal Court in The Hague to allow him to return home to help deal with the siege and its aftermath.
He and Kenyatta face charges of crimes against humanity for their alleged role in coordinating violence that swept Kenya in the aftermath of the contested 2007 elections, when they ran in rival camps. Both deny the charges. They won an election on the same ticket in March.
EMERGING FROM HIDING
The dead in Saturday's assault included children, and the wounded ranged in age from 2 to 78. Many victims were at a cookery competition when assailants opened fire on them, witnesses said. More than 1,000 people were evacuated by security forces combing through the mall, clearing the floors.
An Israeli security source said that Israeli advisers were at the scene helping Kenya to work out how to end the siege.
Kenya's National Disaster Operation Centre referred to a "major engagement" on its Twitter account when a blast was heard. "It's going on, it's going good," one Kenyan soldier who had been in the mall on Sunday told reporters as he left the scene. But later in the evening, the situation appeared calm.
One woman emerged on Sunday morning after hiding under a vehicle in the basement car park. Giving her name as Cecilia, she told Reuters by telephone later that she had seen three men during Saturday's attack who looked like Arabs, judging by their skin colour.
"They were shooting from the exit ramp, shooting everywhere," she said. "I saw people being shot all around me, some with blood pouring from bad wounds. I was just praying, praying 'God, keep me alive' and that my day hadn't come."
Witnesses said the attackers had AK-47 rifles and wore ammunition belts. One militant was shot and arrested early on in the siege, but died shortly afterwards.
The list of foreigners killed including two French nationals, two Canadians, three Britons, a Chinese woman a Dutchwoman and Ghanaian diplomat and poet Kofi Awoonor. The wife of a U.S. diplomat working for the U.S. Agency for International Development was also killed.
Al Shabaab, which is battling Kenyan and other African peacekeepers in Somalia, said Kenyatta must end their mission in Somalia, whose border lies 500 km (300 miles) from Nairobi.
"If Uhuru wants peace from us, he should withdraw his troops from Somalia," said spokesman Abu Musab.
Kenya sent troops into Somalia in October 2011 to pursue militants it blamed for kidnapping tourists and attacking its security forces.
Al Shabaab's last big attack outside Somalia was a twin assault in nearby Uganda, targeting people watching the World Cup final on television in Kampala in 2010, killing 77 people.