Upon landing at Mogadishu airport, I found it hard to ignore certain omens. The carcass of a crashed cargo plane litters the end of the runway. Visible through the crystal-clear water of the Indian Ocean below is the outline of a sunken trading boat, a memento of the struggle with pirates for control of the surrounding sea.

When I arrived last month, the passenger on my right stared down at the plane wreckage below. He was a Western security contractor, one of those seeking the bumper paydays that come from working in a place many international newspapers describe as “the world’s most dangerous city.”

“I saw that plane get hit,” he told me. “A Somali was standing in a fishing boat with an R.P.G., the boat bobbling up and down. He had only one rocket, and boom—it went straight up and took out an engine. You’d never be able to repeat that if you tried a thousand times.

“The plane fell like a stone, but the crew not only survived—they walked away. They climbed out of the cockpit and started unpacking boxes from the back. Ukrainians, they were. Tough people.”

Then he smiled. “It’s not like that now,” he promised. “The bad times are over for Mogadishu. They’re even talking about opening a hotel for the tourists that will soon come back.”

The contractor was, perhaps, being optimistic. As I discovered after we landed, transport for Westerners in most parts of Somalia’s capital city is still only possible in heavily armored military-personnel carriers manned by soldiers wielding Soviet-made 7.62 PKM machine guns. That’s not a good look on a brochure.

I was visiting Mogadishu ahead of the London Conference on Somalia earlier this year, when the big hitters of international diplomacy, among them Hillary Clinton and U.N. Secretary-General Ban Ki-moon, met to try to agree on a way forward for the world’s longest-failed state.

That was clearly going to be no small task. For 20 years Somalia has been in the grip of squabbling warlords, pirate culture, tribal extremism, and religious fanatics. Vast swathes of it remain under the control of the fiercely anti-Western Islamist al Shabaab militia, which this year allied with al-Qaeda. Parts of the country, most importantly Puntland and Somaliland, are de facto independent, so weak is the official government’s authority over its regions.

But talk ahead of the conference was that the worst is over, that al Shabaab is being defeated, and that—finally—an opportunity has arrived to end the impasse that has prevented a nationwide government from taking hold since President Mohamed Siad Barre’s ouster in 1991. I wanted to see for myself if there was any truth to what was being claimed.