MOGADISHU/ANKARA (Reuters) - Turkey opened its biggest overseas military base on Saturday in Somalia’s capital, cementing its ties with the volatile but strategic Muslim nation and building a presence in East Africa.

More than 10,000 Somali soldiers will be trained by Turkish officers at the base, a senior Turkish official said ahead of a ceremony in Mogadishu attended by Turkish military chief of staff Hulusi Akar.

The opening of the $50 million base signals ever-closer ties between Turkey and Somalia. Turkey’s relations with the Horn of Africa date back to the Ottoman Empire, but President Tayyip Erdogan’s government has become a close ally of the Somali government in recent years.

At the opening ceremony on Saturday, Somali Prime Minister Hassan Ali Khaire thanked the Turkish government for opening the training school and said it would help the government “reconstruct” its national force -- “not based on clan...not from a particular place, but well-trained forces that represent the Somali people.”

He noted that the military school was Turkey’s biggest overseas. The facility can train and house 1,000 soldiers at a time and also has sports courts and a running track.

Erdogan, whose roots are in political Islam, is an outspoken defender of Muslims, particularly those in need of humanitarian aid, such as Syrian refugees and Myanmar’s Rohingya.

Analysts say that, in the aftermath of the Arab Spring, as Turkey’s foreign policy forays close to home have floundered, Ankara has found a willing partner in Somalia.

“It’s a country where Turkey could make a difference without necessarily having to compete with regional or global powers,” said Sinan Ulgen, a visiting scholar at the Carnegie Endowment for International Peace. Ankara’s initial focus on aid, as opposed to security assistance or overt backing of political parties, helped build trust, he added.

WINNING HEARTS AND MINDS

Turkey’s vast aid effort at the height of the 2011 famine endeared it to many Somali people, and it has continued to pour in aid, much of it from private companies.

It has built schools, hospitals and infrastructure and provided scholarships for Somalis to study in Turkey. Erdogan has visited Mogadishu twice, and when he made his first trip there in 2011 he became the first non-African leader to visit the war-ravaged nation in 20 years.

Rapidly growing trade between the two nations has followed. In 2010, Turkish exports to Somalia totaled just $5.1 million. By last year, they had ballooned to $123 million. In the space of six years Turkey has gone from Somalia’s 20th-largest source of imports to its fifth-largest.

“Turkey really has won the hearts and minds of Somali people,” Information Minister Abdirahman Omar Osman told Reuters this month.

Somalia’s government has also been a vocal backer of the Erdogan government in its bid to quash Muslim cleric Fethullah Gulen’s influence abroad. The Somali cabinet immediately ordered schools and a hospital in Mogadishu linked to Gulen to be shut in the aftermath of last year’s failed coup, which Erdogan has repeatedly blamed on the cleric. Gulen denies involvement.

SECURITY SUPPORT WELCOMED

Somalia’s government has a number of foreign backers, including the United Nations, the African Union, and the United States, who are assisting it in building a functional national army capable of taking on the fight against the militant al-Shabaab group.

The militants were driven out of Mogadishu in 2010, but their deadly attacks remain one of the main obstacles to stability in the chaotic Horn of Africa country, which lies along one of the world’s busiest shipping routes.

The Somali government has praised Turkish investment for improving infrastructure in the country, and the information minister singled out Turkey’s new move into security support.

“We are very happy they are giving us modern facilities for our security forces,” he said.

“This is something that Somalia has never seen even though countries like the U.S. and UK are giving us millions. The difference is the camp Turkey built is an institution that will remain for the next 50 or 100 years.”

The Turkish official who spoke to Reuters before the opening said the base was in line with Ankara’s priority of expanding its weapons sales “to new markets”.