Somalia’s President Mohamed Abdullahi Farmajo has cut some of the prime minister’s powers in the latest twist in a bitter rift between the two men.
He accused Mohamed Hussein Roble of “taking reckless steps that could lead to a political and security crisis”.
The dispute raises fears of armed conflict on the streets of Mogadishu between rival forces.
The row has been fuelled by the mysterious disappearance of a female spy, Ikran Tahlil, 25.
She was last seen at the end of June, leaving home in a government vehicle.
The intelligence agency said that Ms Tahlil had been kidnapped and killed by al-Shabab, an al-Qaeda affiliate which has been waging a brutal insurgency in Somalia and which still controls many rural areas of the country.
However, al-Shabab denied the allegation. It normally says when it has killed government agents.
The prime minister subsequently suspended the head of the intelligence agency, Fahad Yasin, accusing him of defying his order to report, within 48 hours, on what had happened to the spy.
But the president intervened, saying the prime minister had no authority to sack Mr Yasin – and reinstated him.
The president also rejected the prime minister’s decision to sack the security minister.
The president has appointed a commission of inquiry to look into the disappearance of Ms Tahlil, but the spy’s mother, Qali Mohamud, dismissed the move, saying she wanted a military court to investigate.
In the latest development, the president’s office said in a statement that the prime minister’s powers – especially over the appointment and dismissal of officials – had been withdrawn until Somalia held elections.
The Horn of Africa nation is scheduled to hold indirect parliamentary elections between 1 October and 25 November.
On Sunday, UN deputy head Amina Mohammed met the president and prime minister and urged them to avoid any moves that “could lead to violence and further delay the elections or undermine its credibility”.
The two men were involved in a bitter feud in April over the president’s decision to delay elections, and extend his term in office.
It led to rival factions of the army clashing in the capital, Mogadishu.
Somalia’s security services divided
Analysis by Muhyadin Roble, BBC Somali service editor
This latest escalation of the dispute between President Mohamed Abdullahi Farmajo and Prime Minister Mohamed Hussein Roble is deeply alarming.
Security chiefs are already divided into the two camps.
The National Intelligence and Security Agency (NISA) has two acting heads, one appointed by the president and another by the prime minister.
The commander appointed by the president currently controls the agency’s headquarters, while the one appointed by the prime minister operates outside the agency’s base but still controls its finances, according to government sources.
The military and police commanders are also divided.
These tensions have renewed fears of armed clashes
Rival sets of government troops have already battled for control of parts of Somalia’s capital, Mogadishu, several times recently.
The most recent one was earlier on Thursday, when police units fought part of the military over land disputed by private individuals.
These deep divisions in Somalia’s political and military leadership could also make the country more vulnerable to attack by militant group al-Shabab.
And discussions about the long-delayed elections also look likely to take to a back seat, adding another element to Somalia’s political crisis. The president’s term of office expired in February.