Relations between Middle East heavyweights Iran and Saudi Arabia have been fraught for decades as they spar over regional influence and religion.
Each considers itself to be the guardian of one of the main branches of Islam: Saudi Arabia is ruled by a Sunni royal family while Iran is led by Shiite clerics.
On Friday, Iran and Saudi Arabia said they had agreed to restore ties severed in 2016 and to reopen diplomatic missions "within two months".
Here is a look back at the long years of rocky relations that preceded Friday's thaw.
- Iranian revolution, war -
After the creation of the Islamic Republic of Iran in April 1979, Sunni governments accuse the fledgling state of seeking to "export" its revolution.
In 1980, Saddam Hussein's Iraq attacks Iran, triggering an eight-year war in which Saudi Arabia provides extensive financial support to the dictator.
- Pilgrims killed, ties cut -
In July 1987, Saudi security forces in the Muslim holy city of Mecca crack down on an unauthorised anti-US protest by Iranian pilgrims. More than 400 people are killed, most of them Iranians.
Angry demonstrators ransack the Saudi embassy in Tehran and, in April 1988, Riyadh breaks off diplomatic relations for several years and Iranian pilgrims stay away from the Saudi holy places until 1991.
- Opposing sides in Syria, Yemen -
As Arab Spring demonstrations sweep the region in 2011, Saudi Arabia sends troops to Bahrain to free up its neighbour's forces to crush Shiite-led protests for an elected prime minister. Riyadh accuses Tehran of stoking tensions.
The rival capitals square off again in 2012 as civil war takes hold in Syria. Iran backs President Bashar al-Assad and provides him with military forces and funds to battle Sunni rebels.
Saudi Arabia backs the rebels, but joins a US-led coalition formed to fight Sunni extremists of the Islamic State group from 2014.
Saudi Arabia and Iran also take opposing sides in the Yemen conflict: in March 2015, as Tehran-backed rebels are poised to overrun most of the country, Riyadh leads a military intervention in support of the embattled government.
Riyadh and Washington accuse Tehran of arming the rebels, a charge it strongly denies.
- Deadly hajj stampede -
A stampede at the annual hajj pilgrimage in September 2015 leaves around 2,300 foreign pilgrims dead, including hundreds of Iranians.
Iran's supreme leader Ayatollah Ali Khamenei says the Saudi royal family does not deserve to manage Islam's holiest sites.
- Ties cut again -
In January 2016 Saudi Arabia executes prominent Shiite cleric Nimr al-Nimr, a driving force behind anti-government protests, on terrorism charges.
Iran is furious. Protestors attack Saudi diplomatic missions in Iran, and Riyadh again severs ties.
- Hezbollah, Qatar -
In March 2016, Gulf Arab monarchies blacklist Iran-allied Lebanese Shiite militant group Hezbollah, as a "terrorist" organisation.
In November 2017, it is from Riyadh that Lebanese Prime Minister Saad Hariri announces his resignation, citing Iran's "grip" on his country through Hezbollah. He later recants.
In June 2017, Saudi Arabia and its allies break off diplomatic relations with Qatar, accusing it of being too close to Iran and backing extremism, accusations Doha denies. Saudi Arabia and its allies restore relations in January 2021.
- Iran nuclear accord -
In October 2017, Saudi Arabia says it backs US President Donald Trump after he refuses to certify a 2015 deal aimed at limiting Tehran's nuclear activities.
On March 15, 2018 Saudi Crown Prince Mohammed bin Salman warns in a US television interview that if Tehran gets a nuclear weapon, "we will follow suit as soon as possible".
The prince refers to Iran's supreme leader as "the new Hitler".
"He wants to create his own project in the Middle East, very much like Hitler who wanted to expand at the time," the prince says.
- Restoring relations -
On March 10, 2023, the two sides agree to "resume diplomatic relations and reopen embassies and missions within two months," according to a tripartite statement signed by Riyadh, Tehran and Beijing.
The China-brokered deal was announced while the parties were in Beijing for talks that started on March 6.
Under the agreement, the foreign ministers of Iran and Saudi Arabia will meet to "implement" the deal.
During the meeting, they will arrange for the return of their ambassadors and discuss means of enhancing relations.