Egypt's top court has upheld a deal to transfer two Red Sea islands to Saudi Arabia.

Situated between the two countries, the islands of Tiran and Sanafir are largely unoccupied but they lie in a strategically important and politically sensitive area.

The agreement was first announced during a visit to Cairo in April 2016 by Saudi King Salman bin Abdulaziz Al Saud, during which he announced a multi-billion-dollar package of investments and soft loans for Egypt.

{articleGUID}

Following the signing of the deal, widespread protests broke out across Egypt.

Opponents of the agreement said it amounted to selling off Egypt's sovereign powers and that it violated the constitution, which bars the surrender of any territory.

Saturday's decision by the Egypt Supreme Court nullifies the contradictory rulings two other lower courts had given, with the Supreme Administrative Court opposing ceding control of the islands and the Court of Urgent Matters approving the deal.

The Supreme Court ruled the deal was not unconstitutional, adding that approving the deal was down to Egypt's legislative body.

The Egyptian parliament debated and approved the handover in June last year, with President Abdel Fattah el-Sisi ratifying it a week later.

{articleGUID}

The government then said Tiran and Sanafir belong to Saudi Arabia but had been leased to Egypt in the 1950s.

Yehia Ghanem, Al Jazeera Middle East analyst, said Saturday's ruling is important for the regime and that the Supreme Court decision has granted it legitimacy.

"Today's ruling proves that the Constitutional Court, which is the highest judiciary court, is really part of the regime," he said.

"In the light of the total absence of democracy, these things happen."

The Supreme Court's decision comes several weeks before presidential elections in the country.

Sisi runs largely unopposed and is expected to win an easy victory after his most important challengers stepped out of the race for office.