Somali President Mohamed Abdullahi Farmajo and Prime Minister Mohamed Hussein Roble have reportedly agreed to end a bitter rift that had threatened to derail the country's long-delayed elections.
The row between the two leaders had also risked splitting Somali security forces.
It was sparked by the government’s handling of the disappearance in June of a female spy, Ikran Farah, leading to the appointment of parallel intelligence chiefs and security ministers.
On Thursday, President Farmajo and Mr Roble held their first face-face meeting in several weeks in Mogadishu.
According to a statement read by government spokesman Mohamed Ibrahim Moalimu, they agreed that Abdullahi Mohamed Nur, who was appointed by the prime minister as security minister, would stay in the post.
Under the agreement, Yasin Farey, who was picked by the president as the acting spy chief, would continue to hold the role until a replacement is named.
The two leaders also agreed that the case of missing female intelligence agent would be left to the courts to decide.