JOHANNESBURG, South Africa — Cafes were humming with a weekend lunch crowd. Visitors were anticipating a competition for child chefs. Suddenly, Nairobi's Westgate Mall erupted in gunfire and explosions, sending people scurrying for safety, barricading themselves in storerooms and kitchens. Some played dead.

At least 39 people were killed and 150 wounded Saturday in Kenya's worst terrorist attack in 15 years, President Uhuru Kenyatta said. The Shabab, a Somali group linked to Al Qaeda, claimed responsibility, saying the attack was retribution for the country's invasion of its eastern neighbor two years ago that was aimed at controlling the Islamic militants.

As Saturday night turned into Sunday, security forces were reported to have surrounded attackers still holding an unknown number of hostages in the upscale shopping complex. The Shabab said it was in touch with militants in the mall and rejected negotiations to free the hostages.

"The Kenyan government is pleading with our mujahedin inside the mall for negotiations," it said in a Twitter message shortly before its account was suspended. "There will be no negotiations whatsoever at Westgate."

PHOTOS: Kenya mall attack

Witnesses who escaped the mayhem said gunmen fired at people from an upper floor, and terrified shoppers scrambled to get out of the building, some crawling on their hands and knees. The attack left pools of blood, bodies, discarded shoes, broken glass and spent cartridges.

The assault on a crowded mall, a favorite haunt of affluent Kenyans, diplomats, expatriates and tourists, appeared to be designed to exact maximum casualties and international media exposure. However, it seemed intended primarily to punish Kenya rather than to target foreigners.

Among the dead were two Canadians, including a diplomat, and two French citizens, officials of those countries said. Secretary of State John F. Kerry said there were no reports of Americans being killed, but the wife of an employee of the U.S. Agency for International Development had died. Four Americans were reported injured.

Kenyatta said he had lost some close family members in the attack.

Military and police helicopters flew over the shopping mall as ambulances rushed victims to nearby hospitals. The Kenyan army and special forces were called in to reinforce police. Kenya's Citizen TV aired video of victims arriving by ambulance at hospitals, including some who had been shot in the head and others covered with blood but walking.

It was unclear how many attackers there were. Kenyan news reports said that two suspects had been killed by police or special forces.

The masked gunmen, said to have entered the mall through a cafe on a veranda, reportedly let Muslims go and targeted non-Muslims. Kenya's Daily Nation newspaper reported that people who couldn't recite Muslim prayers were killed.

Umar Ahmed, an 18-year-old who was injured by a grenade, told Kenyan television he was in the rooftop parking area when he heard shooting and screams. He tried to flee, but a gunman saw him and threw a grenade toward him.

"I got scared," Umar said. "I tried to run down the stairs and saw someone running toward the top. I ran back and hid behind one of the cars."

He said he played dead. A gunman turned him over to make sure he was dead and then left him lying there.

Children were among the dead. Westgate Mall is always crowded but had attracted extra visitors for a Junior Super Chef competition, one in a series being held each Saturday for chefs ages 8 to 16.

One man told the BBC he had hidden in a storeroom before being beckoned by restaurant staff into a kitchen, where a group of people had sought safety, barricading the doors with giant refrigerators.

Another witness told Citizen TV that he saw a foreign gunman change his clothes, putting on a maroon shirt and jeans and then mingling with people escaping from the mall. He said he told police, who took no action. Cafe employee Patricia Kuria told reporters she saw two gunmen wearing black turbans.

The assault reminded many Kenyans of Al Qaeda's 1998 attack on the U.S. Embassy in Nairobi, which killed more than 200 people, most of them Kenyans.

The Shabab has launched small-scale attacks since Kenyan armed forces invaded Somalia two years ago, but Saturday's was by far its most severe. Like previous terrorist operations in Kenya, the assault is likely to severely affect the tourist trade, which is vital to the country's economy.