MOGADISHU, Somalia (AP) — During the years when Mogadishu resembled one big battlefield, the U.N. and other aid workers trying to improve Somalia often lived in the comfortable, modern and largely safe capital of Kenya.

As security improved in Mogadishu over the last two years and the lives of Somalis returned to a semblance of normal, those jobs began shifting from Nairobi back to Mogadishu.

On Wednesday, a truck bomb and gunfire attack by al-Shabab militants on the main U.N. compound in Mogadishu killed eight U.N. employees and five Somali civilians, showing just how dangerous that shift has been.

A U.N. official told The Associated Press on Thursday that in the weeks preceding the attack the threat level had been elevated around the city's airport, the heart of military and diplomatic efforts in the city. The militant attack took place just across the street.

A second U.N. official said the Mogadishu operations have been under a consistent threat for years but that he wasn't aware of a specific, elevated threat. Both U.N. officials insisted on anonymity because they are not authorized to speak publicly.

The attack may give even more pause to aid workers who have been hesitant to transfer their work from Nairobi to Mogadishu.

"It's not going to make it easier to attract people to work in Mogadishu," said Ben Parker, the spokesman for the U.N. mission in Somalia. He added later: "I have not heard of anybody talking about quitting because of this incident ... You probably wouldn't have taken a job in Mogadishu if you were risk averse."

U.N. Secretary-General Ban Ki-moon, who was on a visit to Beijing on Thursday, expressed outrage at the "despicable" attack and the said the U.N. won't be deterred from its work.

The world body is in a difficult spot in Somalia because it must balance two competing objectives: keeping staff safe while also carrying out its mandate to promote the rule of law, human rights, women's empowerment and the protection of children.

Assuring safety and advancing those goals are often at odds, said one of the U.N. officials who insisted on anonymity. But the Somali government has increased demands that the U.N.'s international staff work in Mogadishu, not from remote offices in Nairobi, he said.

"There is a tremendous amount of money that continues to be spent on Somalia with very little visible impact, so the donors themselves are really tired of this. And they are putting a great deal of pressure on us to move forward," the official said.

The U.N. is a voluntary force but for smaller aid groups, a move from Nairobi to Mogadishu might be a job requirement.

"Working here is still a matter of a game chance. Let's not be overly optimistic at this point," said Fadumo Dahir, an aid worker based in Mogadishu. "Many have not yet decided to move back to here. They have instead quit their jobs for safety reasons."

A Nairobi-based aid worker who travels to Somalia said the humanitarian community knows the risks it faces in Somalia but also knows it must return. The worker, who also insisted on anonymity because his organization does not permit him to speak publicly, said many people with experience in places like Afghanistan are volunteering to go to Mogadishu.

"Maybe yesterday changes the perspective a little. Maybe it decreases the overall number of people" willing to go, he said. But everyone who is there understands the risk, he said.

The aid worker said reports had circulated in recent weeks of an increased security threat, though no governments made any public announcements. In April, al-Shabab militants carried out a massive attack on Mogadishu's court complex. Britain's Foreign Office released a travel warning on Somalia two days before.

Parker, the U.N. spokesman, said the U.N. clearly faces risks in Mogadishu but he wasn't aware of an elevated threat level. The U.N.'s Assistance Mission in Somalia, though, only opened on June 3, and Parker said he was too new to properly evaluate the threat level.

Parker said he took the job in Mogadishu because it's an exciting time in the seaside capital as the country seems like it is at a turning point toward the positive.

On Thursday, the U.N. worked to recover personal belongings from the targeted compound, including passports. A security review will take place but the U.N. doesn't plan to abandon the targeted compound, Parker said.

The aid worker said a dark cloud was hanging over the humanitarian community Thursday, with many still in shock.

"You feel it in the air," he said. "Everyone is very sad, and some are traumatized."

___

Straziuso reported from Nairobi, Kenya.