Somali President Mohamed Abdullahi Mohamed has ordered an investigation into what he called an "unfortunate tragedy" as the country buried a minister killed by another official's guards.

Mohamed on Thursday cut short his trip to Ethiopia and prayed at the coffin of Abbas Abdullahi Siraji, the 31-year-old minister of public works and reconstruction, who was shot dead on Wednesday outside the presidential palace in the capital, Mogadishu.

In a series of posts on Twitter, Mohamed, known by his nickname Farmajo, said he would "make sure the perpetrators are brought to book".

He also said that Siraji was "young, diligent and patriotic".

READ MORE: Somalia leader declares country a 'war zone'

Siraji was killed when bodyguards tasked with protecting Nur Jimale Farah, auditor-general, apparently mistook the minister, who was driving himself in a following vehicle, for an assailant.

Farah said: "What happened was gunfire involving soldiers who had become suspicious of each other, and what happened was very bad - a brother was killed."

He also asked to not "speculate about the details before the results" of the investigation become available.

Three soldiers have been arrested in connection with the killing, police said.

Police spokesman Qaasim Ahmed said two of the arrested soldiers were among the auditor general's bodyguards and the third was a bodyguard of the late minister.

It is rare for a government minister to drive himself, making mistaken identity a strong possibility.

Many government officials, wealthy individuals and foreigners drive around Mogadishu, a city that has been frequently targeted by armed group al-Shabab, with squads of armed bodyguards who are often nervy and trigger happy.

Inspiring to many

Siraji, a former humanitarian worker, was born in Somalia but grew up and was educated in one of the world's biggest refugee camps, Dadaab, in neighbouring Kenya. He was elected a member of parliament last year and became a cabinet minister in February.

His story was seen as inspiring to many in a country that has suffered conflict and anarchy for the last 25 years and his death has been widely mourned, including on social media.

The African Union Commission’s Chairperson Moussa Faki Mahamat offered condolences.

“My sincere condolences to the family of Minister Abbas Abdullahi Siraj, the government and people of Somalia. The AU stands in solidarity with you,” Mahamat said in a statement posted on his Twitter account.

Former Somali government minister Abdi Aynte wrote on Twitter of the "pain and agony" of Siraji's death while others posted videos of their grief on Facebook.

Inside Story - Why does Somalia matter?

Source: News agencies