A car bomb has exploded outside a hotel in Mogadishu where a Turkish delegation had been preparing for the visit of President Erdogan to Somalia on Friday.
At least two people – both police officers – are said to have been killed as well as a suicide bomber.
One report by AFP quoting police said five Somalis had died.
None of the Turkish delegation was hurt and officials say the president’s visit will go ahead.
Recep Tayyip Erdogan condemned the attack, for which militants from al Shabaab have claimed responsibility.
“If they’re saying this was in the name of Islam… I am a Muslim. There is no such thing in Islam. Firstly, a Muslim cannot commit suicide. Who are they killing? Other Muslims. Islam is not like this,” he said.
“Humanity must display a common stance against anti-Semitism, Islamophobia, racism, discrimination and against attacks targeting holy values.”
Turkey’s Prime Minister Ahmet Davutoglu said an investigation was underway to determine whether the country’s delegation was deliberately targeted.
Al Shabaab, which has carried out attacks across east Africa including a 2013 raid on a Nairobi shopping mall that killed 67, mentioned neither Turkey nor its president in claiming it had carried out the attack.
Turkey is a key ally of the Somali government. It was a major contributor to the humanitarian aid effort at the height of the 2011 famine and Ankara continues to build hospitals and dispatch aid across Somalia.