Cheers echoed throughout the courtroom as a top Egyptian court handed down its final ruling on Monday, rejecting the government's plan to hand two Red Sea islands over to Saudi Arabia.

But, while many Egyptians are teeming with national pride, the decision will likely further sour relations between Cairo and Riyadh, which has showered the struggling country with tens of billions in aid in recent years.

The controversial agreement on the islands of Tiran and Sanafir has been making its way through Egyptian courts over the past year. In June, the court annulled the agreement, arguing that Egypt's sovereignty over the islands couldn't be given up. The Egyptian government appealed and the court agreed to accept the appeal.

In the end, the court's annulment has been upheld. Here's how the saga unraveled.