An Egyptian court on Wednesday overturned a decision by President Mohamed Morsi to sack prosecutor general Abdel Meguid Mahmoud and ordered his reinstatement, state media reported.
The ruling by the appeals court will once again put the presidency on a collision course with the judiciary, while any enforcement of its terms remains trapped in a legal labyrinth.
Morsi sacked Mahmud in November, in a decree that granted the president sweeping powers and placed his decisions beyond judicial review. Mahmud was replaced by current prosecutor general, Talaat Abdallah.
The decree was eventually repealed under immense street pressure, but the decisions stemming from it were protected by the constitution that was passed in December.
Wednesday's ruling comes because the court believes that Morsi acted outside his executive jurisdiction in sacking Mahmud, but "it faces big obstacles," said Khaled Abubakr, a prominent lawyer.
"There is a court decision that needs to be applied, but at the same time there is a decree that is protected by the constitution," he told AFP.
The decision will intensify long-running tensions between the presidency and the judiciary which accuses Morsi of interfering in its independence.
"The solution is for a higher court, like the Supreme Constitutional Court, to rule on the crisis," Abubakr said.
"Legally, we now have two prosecutor generals," said Abubakr.
Mahmud himself, in a statement, said he had not yet decided on what action to take but was "happy with the ruling, which stresses the independence of the judiciary."
Morsi appointed current prosecutor Abdallah in December in one of a number of decisions that sidelined judges, sparking a judicial strike and mass rallies by the Islamist president's opponents.
His actions triggered a nationwide outcry, with opposition forces calling it a "coup" and the judges saying it was a direct attack on the independence of the judiciary.