An Egyptian judge has quashed a government decision to hand control of two Red Sea islands to Saudi Arabia.
Egypt's President Abdul Fattah al-Sisi announced that Tiran and Sanafir would be transferred in April, during a visit by Saudi Arabia's King Salman.
More than 150 people were jailed in connection with protests over the deal, though many were later acquitted or had their sentences reduced on appeal.
The Egyptian government has said it will challenge Tuesday's ruling.
Tiran and Sanafir are uninhabited and located at the mouth of the Gulf of Aqaba, a strategic part of the Red Sea bordered by Israel, Jordan, Egypt and Saudi Arabia.
Egyptian troops have been stationed there since 1950 at Riyadh's request.
Mr Sisi's decision in April to cede control of them to Saudi Arabia sparked widespread criticism.
The president was accused of violating the constitution and "selling" the islands in return for a multi-billion dollar aid package unveiled by King Salman during his visit.
But Mr Sisi insisted that Tiran and Sanafir had always belonged to Saudi Arabia.
On Tuesday, Egypt's State Council, an administrative court, issued a verdict annulling April's maritime borders agreement between Cairo and Riyadh.
Cheers in court: By Sally Nabil, BBC News
The maritime border agreement signed earlier this year between Egypt and Saudi Arabia took many Egyptians by surprise.
Since then, protesters have taken to the streets calling the arrangement unconstitutional, and accusing the government of giving away Egyptian territories in return for aid packages and investments worth billions of dollars from Saudi Arabia, a strong backer of President Sisi.
Some of these protesters were arrested and charged with disrupting public order. A few are still behind bars.
The lawsuit was filed by a number of prominent human rights lawyers, headed by a former presidential candidate, Khaled Ali.
When the verdict was issued, many cheered inside the courtroom, chanting "the islands are Egyptian". But the legal battle has not come to an end yet, because the decision can be appealed.
The verdict stated that the two islands would "remain under Egyptian sovereignty".
If it is approved by the country's High Administrative Court it will become legally binding.
However, the State Lawsuits Authority, which represents the Egyptian state in lawsuits, said on Tuesday evening that it would challenge the ruling, state television reported.
Mr Sisi has cracked down on all dissent since leading the military's overthrow of President Mohammed Morsi in 2013.
Since then, more than 1,000 people have been killed and 40,000 are believed to have been jailed, most of them supporters of Mr Morsi's Muslim Brotherhood.
Why the Red Sea islands matter
- Sanafir and Tiran are islands that lie about 4km (2 nautical miles) apart in the Red Sea. Tiran sits at the mouth of the Gulf of Aqaba, on a strategically important stretch of water called the Strait of Tiran, used by Israel to access the Red Sea
- The islands are uninhabited, apart from Egyptian military personnel and multi-national peacekeepers, since 1982
- Egyptian troops have been stationed on the islands since 1950 at the request of Saudi Arabia
- Israel captured the islands in 1956 and 1967, subsequently returning them to Egypt both times
- Egyptian President Abdul Fattah al-Sisi was criticised for "selling" Egyptian territory after deciding in April 2016 to hand the islands to Saudi Arabia