Archrivals Iran and Saudi Arabia agree to end years of hostilities in deal mediated by China

An Iranian protester holds a street sign bearing the name of prominent Shiite Muslim cleric Nimr al-Nimr during a demonstration against his execution by Saudi authorities, on January 3, 2016, outside the Saudi embassy in Tehran.

A version of this story first appeared in CNN's Meanwhile in the Middle East newsletter, a three-times-a-week look inside the region's biggest stories. Sign up here.

Abu Dhabi, UAE (CNN)Saudi Arabia and Iran announced on Friday that they had agreed to reestablish diplomatic ties after seven years of hostility, in a deal between the regional archrivals that could have wide-ranging implications for the Middle East.

Riyadh and Tehran plan to reopen their embassies within two months in an agreement mediated by China, Saudi Arabia and Iran said in a joint statement after talks in Beijing on Friday.
They also plan to reimplement a security pact signed 22 years ago under which both parties agreed to cooperate on terrorism, drug-smuggling and money-laundering, as well as reviving a trade and technology deal from 1998.
    Friday's announcement is also a diplomatic victory for China in a Gulf region that has long been considered part of the US' domain of influence. It comes as the Biden administration tries to notch its own win in the Middle East by trying to broker a normalization pact between Israel and Saudi Arabia.
      Talks had been ongoing since March 6 in Beijing between Iranian national security chief Ali Shamkhani, Saudi national security council adviser Mosaed Bin Mohammad Al-Aiban and China's top diplomat Wang Yi, according to Iranian state media.
      Video of the signing ceremony aired by Iranian media showed officials seated around tables on opposite sides with the Saudi Arabian, Iranian and Chinese flags around them.