The chaos and conflict that once consumed the port of Mogadishu are now gone and a few foreign investors are starting to move into Somalia. Turkey is leading the way - but why is there such a strong bond between these two countries?

Where once rival militias battled for control of these docks, giant container ships now line up to discharge their cargoes of cement, vehicles, pasta and rice. Huge cranes swoop up and down. Some operated by Turks, others by Somalis.

As a container swings uncomfortably close above my head, the sprightly Turkish manager of the port tells me that since his company took over in September, it has been bringing in a monthly revenue of $4m, and rising. Fifty-five percent goes straight to the Somali government.

Find out more Listen to From Our Own Correspondent for insight and analysis from BBC journalists, correspondents and writers from around the world Broadcast on Radio 4 on Saturdays at 11:30 BST and BBC World Service Listen to the programme Download the programme

He won't let me take his photograph. "I'm too ugly," he says.

It's not just the port. Turks are everywhere in Mogadishu. And so is their flag. This visit, I think I saw more Turkish flags in the city than Somali ones.

Turks run the airport and are busy building a new terminal. Turkish Airlines now flies to Mogadishu four times a week, the first international airline to do so in more than 20 years.

At a gleaming new hospital, built by the Turks, Turkish doctors wear simple white polo shirts. On one sleeve is an image of the Turkish flag. The Somali flag is on the other.

Outside, Turkish builders in cowboy hats and Somalis in tatty T-shirts are putting the final touches to an Ottoman-style mosque with room for 2,000 worshippers. Craftsmen were flown in from Turkey to hand paint the ceiling in rich blues, reds and gold.

Even the garbage trucks trying to get rid of the 20 years' worth of rubbish and rubble come from Turkey. I saw one such truck hosing down a street after a suicide bombing, to make sure every trace of blood and wreckage was removed.

It all started with the famine of 2011. The then Turkish prime minister, now president Erdogan, flew to Somalia. Unlike other foreigners, who keep at a safe distance from the country, preferring to do Somali-related business from neighbouring Kenya, he walked through the streets of Mogadishu. In a suit. Not body armour.

Somalis still talk to me about how he picked up dirty, starving children. How his wife kissed members of the despised minority clans.

And hence the love affair began. Somalis called their boys Erdogan, their daughters Istanbul.

Image copyright AFP Image caption Recep Tayyip Erdogan and his wife Emine during their visit to a camp for displaced people in August 2011

This affection for a foreign country is highly unusual in Somalia. Somalis generally do not like outsiders, and have all sorts of abusive nicknames for them. But I struggled to find a Somali who would criticise Turkey, apart from the complaint that they hadn't provided adequate drainage for the new roads they're building in Mogadishu, and that they hadn't done enough to help other parts of the country.

In private conversations, Western diplomats have told me Turkey doesn't communicate or co-ordinate with other donors, that it is too unilateralist.

Turkey, like many other countries, is keen to lay its hands on Africa's natural resources and to exploit new markets as the continent develops. But it has chosen an eccentric way in - Somalia is classed by many as one of the world's most dangerous countries.

The Turks in Mogadishu seem to have a different attitude to danger. On the day of a suicide bombing, I was forbidden access to the highly fortified airport, where I was due to meet the British ambassador.

Image caption Before Turkey resurfaced the roads they were full of holes

But just nearby was a Turkish school, guarded by a couple of lightly-armed Somalis. Turkish children scampered about, playing hide and seek amongst the papaya trees. They share classes with Somali students, who the teachers say are especially good at computing and languages.

The Turks have paid a price for this more relaxed attitude to security. A few have been killed and injured in attacks by the Islamist group al- Shabab; some have been shot dead in disputes over money and other issues.

The next day, I managed with some difficulty to get into the airport compound, this time to meet the United Nations, based in a sterile, grey complex of containers.

Somewhat to my embarrassment, I didn't have a pen. The UN lady kindly lent me a pencil. I forgot to give it back, and later on I gave it to a Somali friend.

Wielding the pencil, he rushed off to his friends shouting, "Look. This is all the UN has to offer us, after more than 20 years and billions of dollars. In just three years, the Turks have helped transform our man-made earthquake of Mogadishu into a semi-functioning city."

Image caption Goods are loaded on to trucks at the port

Of course, it's not as simple as that. The UN and others are paying for African Union soldiers who are helping make Somalia a safer place. The Turks have gone for highly visible projects.

But as I sat eating the cube of Turkish delight offered to me by the sleek stewardess on my homeward Turkish Airlines flight, I couldn't help wondering whether the rest of the world could learn something from what the Turks are doing in the broken city of Mogadishu.

How to listen to From Our Own Correspondent:

BBC Radio 4: Saturdays at 11:30

Listen online or download the podcast.

BBC World Service: at weekends. See World Service programme schedule.

Subscribe to the BBC News Magazine's email newsletter to get articles sent to your inbox.