Egypt’s President Abdul Fattah al-Sisi had announced in April, during a visit by King Salman, that Tiran and Sanafir islands would be handed back to Saudi Arabia.
The decision had sparked protests in the North African country and about 150 people were jailed in connection with these protests.
Tuesday’s verdict is not final. The state has the right to appeal the ruling at a higher court, and the deal needs to be approved by parliament.
The two Islands, Tiran and Sanafir, lie between Saudi Arabia and Egypt’s Sinai Peninsula, at the narrow entrance to the Gulf of Aqaba leading to Jordan and Israel.
Saudi and Egyptian officials say the islands belong to the kingdom and were placed under Egyptian control, at Saudi Arabia’s request in 1950, to secure their protection.
Riyadh has extended significant financial and diplomatic backing to Egypt since President Abdel Fattah el-Sisi toppled President Mohamed Morsi in 2013.