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.
1. It started as a $23 billion trade deal
Saudi Arabia's King Salman visited Egypt in April 2016, and agreed to send 700,000 tons of refined oil products per month for five years under a $23 billion aid deal.
As part of the aid deal with Saudi Arabia, Egypt agreed to hand over two Red Sea islands, Tiran and Sanafir. Saudi Arabia would then build a causeway between the kingdom and Egypt via Tiran, which would have likely benefited Egypt financially.
Regardless, the decision drew significant criticism within Egypt. Challenges to the agreement were brought to the courts, eventually leading to this week's final ruling.
2. But then delays over the island led to Saudi Arabia cuting oil supplies to Egypt
As Egypt failed to quickly hand over control of the two islands and support Saudi Arabia on several key geopolitical issues, tensions grew between the two nations.
In October, Saudi oil stopped coming. Later, in November, Egypt's Oil Ministry revealed that the kingdom had said petroleum shipments would cease "until further notice."
3. Egypt has shifted its focus to Iran
Last week, it was confirmed that Egypt would begin receiving one million barrels of petroleum per day from Iraq.
The Iraqi ambassador to Cairo, Habib al-Sadr, made the announcement. He said the agreement was signed two weeks ago and also includes plans for a direct pipeline between the two countries via Jordan. The amount may also increase moving forward, depending on payment terms.
Rumors have also surfaced that Egypt may be seeking oil from Riyadh's arch-rival, Iran.
In November, a source close to Egypt's Oil Minister Tarek El Molla said that the minister would visit Iran to make a new oil deal, according to Reuters. But, as the news became public, Molla denied plans to visit Tehran. An Iranian oil official also denied the reports.
Two security sources and the source in Molla's delegation told Reuters that the minister had been scheduled to visit Iran, but had delayed the visit after the news became public. Iran and Egypt have had a strained relationship since the 1970s, meaning any oil deal would be a dramatic shift in policy between the two nations.
As it builds stronger ties with Iraq, Egypt already appears to be looking for new geopolitical alliances in the region.
4. Egypt has broken with Saudi Arabia on Syria and Yemen
Last year, Egypt supported a UN Security Council resolution on Syria that was strongly opposed by Saudi Arabia. While Saudi Arabia has maintained support for rebel groups fighting against the Iranian and Russian-backed Syrian President Bashar al-Assad, Egypt has pushed for a political solution that could likely see Assad hold onto power.
Reports have also surfaced that Egypt may have sent military leaders to support the Syrian president.
In Yemen, where Saudi Arabia is leading a coalition fighting against Houthi rebels (which are allied with Iran), Egypt has remained unwilling to join the conflict.
These two disagreements have drawn a wedge between the two governments, particularly as Saudi Arabia becomes less confident in Egyptian President Abdel Fattah al-Sisi's ability to address his country's economic woes.
5. Tiran and Sanafir have been disputed for decades
Control of Tiran and Sanafir has shifted several times over the past century. Some say the islands always belonged to Saudi Arabia and others say they always belonged to Egypt. Both sides claim to have legal documents and agreements to support their claims.
Some experts say that Egypt legally established its territorial claim to the islands in an agreement with the Ottoman Empire in 1906. Egypt clarified these claims in 1954 before the United Nations.
But others say Egypt had merely taken control of the islands in 1949, at the beckoning of Saudi Arabia.
Expecting trouble during the turbulent years of the Arab-Israeli conflict, Saudi Arabia asked Egypt to protect the islands from Israeli invasion. Egypt agreed to the request but lost control of Tiran to Israel when it was militarily taken over by Israeli forces.
Tiran returned to Egyptian control in 1982, fulfilling a key part of Egypt's peace agreement with the Israeli government. Due to the peace agreement's terms, Israel also had to sign off on the Egyptian government's decision to hand the islands over to Saudi control.