MOGADISHU, Somalia (AP) — A World Food Program handout of corn rations to Somalis trying to survive a famine turned deadly Friday after government troops opened fire, killing at least seven, witnesses said.

Residents of Mogadishu’s largest famine refugee camp accused government soldiers of starting the chaos by trying to steal some of the 290 tons of dry rations that aid workers were trying to distribute there. Then refugees joined in the scramble, prompting soldiers to open fire, the witnesses said.

“They fired on us as if we were their enemy,” said refugee Abidyo Geddi. “When people started to take the food then the gunfire started and everyone was being shot. We cannot stay here much longer. We don’t get much food and the rare food they bring causes death and torture.”

The chaos underscores the dangers and challenges of getting help to a nation that has been essentially ungoverned for two decades and now has a severe famine sweeping through it. There are 9,000 African Union soldiers in the capital, but their main mission is to fight al-Qaida linked Islamists, not safeguard humanitarian aid.

Aid workers are puzzling over how to help the starving without helping gunmen who either prey on the refugees, compete for security contracts to guard the food, or steal it and take a share of the profits when it’s sold at market.

The situation echoes the 1992 famine that prompted deployment of a U.S.-led multinational force to safeguard the delivery of food to Somalia’s starving. That international intervention collapsed in 1993 after two U.S. Black Hawk helicopters were shot down and 18 servicemen were killed in one single battle in Mogadishu.

U.S. and U.N. officials acknowledge that some aid in Somalia is bound to be stolen during delivery.

“Will there be losses? Sure. Will there be some looting? Of course there will be. What we have to do is try to minimize it,” said WFP spokesman David Orr. “This is the highest risk environment in the world … the safety of our staff and getting food into the right hands are our highest priorities.”

Friday’s food distribution was organized by Mogadishu’s mayor, and had been delayed two days as officials tried to shore up security arrangements. Orr told The Associated Press that the food distribution started smoothly at around 6 a.m. but degenerated a couple hours later.

“We got reports of trouble, looting. The trucks were overwhelmed by a mob of people. There were reports of some shots fired,” said Orr, who said he could not confirm any death tolls.

One of the camp’s refugees, Muse Sheik Ali, said soldiers first tried to steal some of the food aid, and that other refugees began to take the food.

“Then soldiers opened fire at them, and seven people, including elderly people, were killed on the spot. Then soldiers took the food and people fled from the camp,” he said.

A Western official said the distribution went smoothly until more displaced families and gunmen arrived. The official could not be identified because he is not authorized by his employer to be quoted by the press. No details on which militia the gunmen may have belonged to were available. At least four militias prowl government-controlled areas of Mogadishu, their gunmen roaring around in pick-up trucks.

Thousands of Somalis have flooded into Mogadishu from the drought-stricken south. Many have walked for hundreds of miles and buried family members along the way. The drought and famine in Somalia have killed more than 29,000 children under the age of 5 in the last 90 days in southern Somalia alone, according to U.S. estimates.

Somalia Prime Minister Abdiweli Mohamed Ali visited the camp after the violence and said he was “deeply sorry.” Ali said an investigation would be opened and promised harsh punishment for anyone found guilty.

The already mostly lawless capital has been made even more chaotic with the arrival of tens of thousands of refugees fleeing drought in the south, the famine’s epicenter. International groups face huge challenges in distributing food inside Somalia. The worst-hit part of the country is controlled by al-Qaida-linked insurgents, who deny there is a famine and who have forbidden many aid groups from working there.

More than 12 million people in the Horn of Africa are in need of immediate food aid. The U.N. says 640,000 children are acutely malnourished in Somalia, where the U.N. has declared five famine zones, including the camps in Mogadishu for displaced families.

WFP often tries to do what it calls “wet feedings,” in Somalia — giving out already made food like porridge — to limit the chances that it will be looted. But in this case it was dry rations, Orr said.

Somali soldiers control just part of the capital and are poorly trained.

“It was carnage. They ruthlessly shot everyone,” said Abdi Awale Nor, who has been living at the camp. “Even dead bodies were left on the ground and other wounded bled to death.”

The memory of international intervention in Somalia in 1992, just after the socialist dictatorship of Siad Barre had collapsed into clan warfare, haunts aid workers. Hundreds of thousands of Somalis starved to death, and the spectacle of their suffering rallied the world to send ships full of grain and peacekeepers to guard them.

Since the era of Black Hawk Down, aid groups say they have tried to tighten up their procedures by screening contractors, having independent checks on their operations and requiring truckers to pay a cash bond to ensure the food is delivered. Some say that Somalia is still too volatile to work in: WFP alone has had 14 employees killed in the past three years. Most foreign aid workers pulled out two years ago after a spate of killings and kidnappings.

The African Union peacekeeping force is willing to help safeguard aid deliveries, said Maj. Gen. Nathan Mugisha, the former commander of the AU force. He urged international organizations to do more to feed the families in the places they secured.

“We have done our part, largely, in the security sector,” said Mugisha, whose forces have clawed back government control in about half the capital’s 16 districts. Five more are on the front lines and the rebels control three.

Many aid agencies — some of whom are still able to operate in rebel-held areas — fear that if they are seen to be working too closely with the AU force, their staff could be targeted for being spies.

“Humanitarian responses in Somalia must be civilian-led,” said Mark Bowden, the U.N.’s top official in charge of humanitarian aid in Somalia. “In the highly politicized context of south-central Somalia, relying on military assistance will not be effective. It is important that aid is seen as being impartial and independent of all political action.”