The islands,Tiran and Sanafir, have a patriotic significance for many Egyptians and the accord to handover the islands had sparked protests
An Egyptian court on Tuesday quashed a government decision to hand over two Red Sea islands to Saudi Arabia, judicial sources said, over-ruling a deal that had sparked public outrage.
President Abdel Fattah al-Sisi announced the controversial accord in April during a visit to Cairo by Saudi King Salman.
A judge told AFP that the decision by the State Council, Egypt's highest administrative court, "cancels the signing" of the deal, which put two islands in the Straits of Tiran under Riyadh's control.
The handover prompted an outcry from many Egyptians and sparked protests against Sisi.
A court last month sentenced 51 people to two years in jail for taking part in protests against the accord.
In the lead-up to the protests, police already made dozens of arrests to discourage a repeat of a large rally on April 15 at which demonstrators chanted for the "fall of the regime".
Egypt's appeals court in May overturned five-year jail terms for 47 people convicted of taking part in non-authorised protests, but upheld fines of more than $11,000 each.
Tuesday's ruling on the islands deal is not final and may be challenged by the government.
Lawyer Khaled Ali, who brought the case, told AFP the court's verdict "shows that the two territories are Egyptian... and cannot be given away".
Saudi Arabia is one of Sisi's main regional backers, and the kingdom has provided Egypt with billions of dollars worth of aid and investment since the former army chief took power.
Although generations of Egyptians have grown up believing the islands belonged to Egypt, Cairo insists they have always been Saudi territory, which was leased to it in 1950 following a request by Riyadh.
Many Egyptians view Tiran and Sanafir with patriotic fondness because of the islands' association with the four wars Egypt fought with Israel between 1948 and 1973.
Lying at the mouth of the Gulf of Aqaba, the islands can be used to control access to the Israeli port of Eilat. They were captured by Israel in the 1967 Arab-Israeli war before being returned to Egypt under the 1979 Camp David Accords.
Cairo says the transfer agreement was based on a presidential decree issued by now ousted leader Hosni Mubarak who in 1990 even informed the United Nations about the matter.
Critics accuse Sisi of "selling" the islands in return for Saudi investments.
The judge, who declined to be named due to the sensitivity of the issue, said Tuesday's verdict stressed that the two territories remain "Egyptian".