An Egyptian court has rejected a government plan to transfer two uninhabited Red Sea islands to Saudi Arabia, in a final ruling that prompted cheers in the courtroom but could deepen tensions with the country's erstwhile financial backer. Egypt's government had announced in April, during a visit by the Saudi king, a maritime demarcation accord that would mean it cedes control of Tiran and Sanafir. The deal prompted protests from Egyptians who said they had been taught in school that the islands belonged to them.

It has become a source of tension between Egypt and Saudi Arabia, which has showered its ally with tens of billions of dollars in aid in recent years but suspended petroleum supplies in September amid growing differences. The court's decision was based on “irrefutable evidence” as well as local and international practices which removed any doubt that the islands belonged to Egypt alone, state news agency MENA said.

Egyptian lawyer and former presidential candidate Khaled Ali celebrates outside the State Council courthouse after the Egypt-Saudi border demarcation agreement (EPA)

Two leading human rights lawyers had challenged the demarcation accord in Egypt’s administrative court system, which deals with cases involving the government and public entities. One of them, Khaled Ali, called the verdict a “decisive” ruling. “So it is not permissible for the president, or prime minister or parliament or cabinet or a referendum to give up this land,” Ali said. “It is Egyptian land and cannot be given up according to the Egyptian constitution.”

The lawyers won an initial ruling in June, but the government appealed, sending the case to the Higher Administrative Court which sits atop the administrative judicial ladder.

Celebrations erupted as the judge read out the ruling, with jubilant supporters carrying Ali and his colleague Malek Adly out of the courtroom.

Hundreds of people outside waved Egyptian flags chanted "Egyptian, Egyptian" and "Bread, Freedom, the islands are Egyptian".

"This verdict is a victory for Egypt," Adly said.

There was no immediate response from the government. Saudi and Egyptian officials had argued that the islands belonged to Saudi Arabia and were only under Egyptian control because Riyadh asked Cairo in 1950 to protect them.

But the lawyers who opposed the accord said Egypt's sovereignty over the islands dated back to a treaty in 1906, before Saudi Arabia was founded.