Lawyer Khaled Ali celebrates after the Supreme Administrative Court said two islands could not be transferred to Saudi Arabia, Jan. 16, 2017. (Amr Nabil/AP)

A top Egyptian court on Monday overruled a government plan to transfer sovereignty of two Red Sea islands to Saudi Arabia, dealing an embarrassing and unexpected setback to President Abdel Fattah al-Sissi and his attempts to reward financial benefactors in the Persian Gulf region.

The verdict, by Egypt’s Supreme Administrative Court, rejected a government appeal of an earlier court ruling, and was “final,” said Khaled Ali, one of the lawyers who challenged the transfer.

The plan to hand over the uninhabited islands had sparked unusually large protests in Egypt, shocking officials and defying a ban on demonstrations. Many Egyptians saw the possible loss of territory as overreach by an unaccountable government as well as an intolerable attack on identity, with the islands representing, for some, the country’s steady loss of independence and regional clout.

Saudi Arabia and other Gulf nations have propped up Egypt’s faltering economy with billions of dollars in aid since 2013, when the military, led by Sissi, ousted President Mohamed Morsi, an Islamist leader from the Muslim Brotherhood and the country’s first democratically elected leader.

During a visit to Egypt by King Salman of Saudi Arabia in April 2016, the government announced it was transferring the two islands, which sit at the mouth of the Gulf of Aqaba and are called Tiran and Sanafir. Officials said that the islands belong to Saudi Arabia and that Egypt had taken control of them in the 1950s, out of concern Israel would seize them. 

The backlash was immediate, with Egyptians criticizing the decision and mocking the government on social media. The fury of the reaction, which included one of the largest demonstrations in years, suggested that the nationalism Sissi’s government had stoked for several years to shore up its own legitimacy had suddenly backfired: For many, the giveaway of the islands was a red line, whether they belonged to Egypt or not.

The judges of the administrative court ruled Monday that Egypt’s sovereignty over the islands was “irrevocable.” Celebrations broke out in the courtroom when the verdict was read, and outside the court, protesters chanted against Sissi, according to the Egyptian novelist Ahdaf Soueif, who attended the hearing and posted updates on Twitter.

“The chants are: bread freedom social justice,” she wrote, “and down down with military rule.”

The future of the proposal remains uncertain. Egypt’s parliament has been debating the transfer of the islands, and the government, separately, has challenged the jurisdiction of the administrative court to rule on the matter. Also left unresolved is the fate of dozens of protesters who were arrested during demonstrations against the transfer of the islands and are facing criminal charges.  

Fahim reported from Istanbul.