The regional rivals are expected to reopen embassies within two months as ties including security agreement are restored after Beijing talks.

Iran and Saudi Arabia have agreed to re-establish ties and reopen embassies within two months, according to Iranian and Saudi state media.

The agreement came after talks held in the Chinese capital, Beijing.

“As a result of the talks, Iran and Saudi Arabia agreed to resume diplomatic relations and re-open embassies … within two months,” Iranian news agency IRNA reported on Friday.

Nour News, which is linked to Iran’s Supreme National Security Council, posted images and video it described as being taken in China with the meeting. It showed Ali Shamkhani, the council’s secretary, with a Saudi official and a Chinese official that state TV named as Wang Yi.

“After implementing of the decision, the foreign ministers of both nations will meet to prepare for exchange of ambassadors,” Iranian state television said.

The Saudi Press Agency confirmed the agreement when it also published the joint statement from Saudi Arabia and Iran, which said that the two countries had agreed to respect state sovereignty and not interfere in each other’s internal affairs.

The statement also said that Riyadh and Tehran had agreed to activate a security cooperation agreement signed in 2001.

Tensions have long been high between the regional rivals.

Saudi Arabia broke off ties with Iran in 2016 after protesters invaded Saudi diplomatic posts there.

Saudi Arabia had executed a prominent Shia Muslim scholar days earlier, triggering the demonstrations.

But there have been more recent efforts on both sides to warm ties.

“In the last couple of years, there had been meetings between Saudi and Iranian officials in Baghdad,” said Al Jazeera’s Ali Hashem. “The Iraqis started mediation talks back in 2021. Everything stopped during the Iraqi elections of 2021,” he said.

“There was no news comings out after five rounds of talks. Security-level meetings took place in Oman, too. Those were mainly concentrated on the situation in Yemen.”

Iran and Saudi Arabia are on rival sides of a number of regional issues, in countries as varied as Lebanon, Syria and Yemen.

Improved relations between Tehran and Riyadh could therefore have an effect on politics across the Middle East.

“The security situation in the region, like in Yemen and Lebanon, deteriorates and suffers when these two countries have differences,” said Hashem. “With this deal, it is possible that we might start to see compromises in these countries. This deal can lead to the creation of a better security situation in the region. They have a lot of leverage in these countries.”