Diplomatic relations between Iran and Saudi Arabia have been tense since the 1979 Islamic Revolution, though there have been occasional thaws between the two rivals.

The tensions have now sharply escalated with Saudi Arabia severing ties with the Islamic Republic following attacks on Saudi diplomatic missions in Iran. Here's a look at how relations between the two Mideast powers have shifted over the last decades:

PRE-REVOLUTION RELATIONS: Under the rule of Shah Mohammad Reza Pahlavi, Iran had rocky relations with Saudi Arabia, though they improved toward the end of his reign. Both were original members of the oil cartel OPEC.

POST-REVOLUTION: After the overthrow of the shah and takeover of the U.S. Embassy in Tehran, Saudi Arabia quickly became America's top ally in the region. In the ensuing 1980s war between Iran and Iraq, Saudi Arabia backed Iraq despite its concerns about dictator Saddam Hussein. That war would kill 1 million people.

1987 HAJJ RIOTS: The annual pilgrimage to Islamic holy sites in Saudi Arabia, required of all able-bodied Muslims once in their life, saw bloodshed when Iranians held a political demonstration. Iranian pilgrims later battled Saudi riot police, violence that killed at least 402 people. Iran claimed 600 of its pilgrims were killed and said police fired machine guns at the crowd. In Tehran, mobs attacked the Saudi, Kuwaiti, French and Iraqi embassies, ransacking the first two.

SEVERING TIES: In 1988, Saudi Arabia severed ties with Iran, citing the 1987 hajj rioting and Iran's attacks on shipping in the Persian Gulf. Iranians responded by boycotting the hajj in 1988 and 1989. The two countries restored diplomatic ties in 1991.

EASING TENSIONS: Relations between the two nations improved after Iranian President Mohammad Khatami, a political moderate, took office in 1997. Ties warmed further after historic visits by Saudi Crown Prince Abdullah to Tehran in December 1997 and Khatami to the kingdom in May 1999.

NUCLEAR DISPUTE: Worries about Iran resumed in Saudi Arabia amid international sanctions against Tehran over its contested nuclear program and the increasingly harsh rhetoric of Iranian President Mahmoud Ahmadinejad. Iran and Saudi Arabia each backed opposite sides in Syria's civil war, as well as in the civil war in Yemen. Saudi Arabia also grows increasingly suspicious of Iran as it reaches a deal with world powers over its nuclear program.

2015 HAJJ DISASTER: On Sept. 24, a stampede and crush strikes the annual hajj pilgrimage in Saudi Arabia. While the kingdom says 769 pilgrims are killed, an Associated Press count shows over 2,400 people were killed. Iran says at least 464 of its pilgrims were killed and blames Saudi Arabia's "incompetence" for the deaths.

SHEIKH'S EXECUTION: On Jan. 2, Saudi Arabia executed Shiite cleric Sheikh Nimr al-Nimr and 46 others — the largest execution carried out by the kingdom in three and a half decades. The execution of al-Nimr, a central figure in Arab Spring-inspired protests by Saudi Arabia's Shiite minority, sparked protests across the Mideast and attacks on Saudi diplomatic facilities in Iran. Saudi Arabia responded by announcing it was severing diplomatic ties with Iran over the attacks.

___

Follow Jon Gambrell on Twitter at www.twitter.com/jongambrellap .