Top diplomats from Middle East rivals Iran and Saudi Arabia met in Beijing on Thursday, resuming diplomatic relations and pledging to work together to bring "security and stability" to their turbulent region.

In a joint statement released after talks between Iranian Foreign Minister Hossein Amir-Abdollahian and Saudi counterpart Prince Faisal bin Farhan, the two sides vowed to continue to work together to improve ties.

The meeting came after a surprise China-brokered deal in March put Tehran and Riyadh on a path to restore relations that had been severed seven years ago when protesters in Iran attacked Saudi diplomatic missions.

"The two sides emphasised the importance of following up on the implementation of the Beijing Agreement and its activation in a way that expands mutual trust and the fields of cooperation and helps create security, stability and prosperity in the region," Thursday's joint statement said.

Chinese Foreign Minister Qin Gang "witnessed the signing of a joint statement between Saudi Arabia and Iran, and the two countries announced the resumption of diplomatic relations with immediate effect", the ministry said.

French President Emmanuel Macron and EU chief Ursula von der Leyen were also in the Chinese capital Thursday, seeking to make Europe's case in a meeting with Xi Jinping for bringing an end to the conflict in Ukraine.

Macron, in joint remarks to the media alongside Xi, welcomed the Iran-Saudi thaw as he congratulated his Chinese counterpart for securing "this important step forward".

- Shock rapprochement -

The shock rapprochement between mainly Sunni Muslim Saudi Arabia, the world's biggest oil exporter, and Shiite-majority Iran, strongly at odds with Western governments over its nuclear activities, has the potential to reshape relations across a region characterised by turbulence for decades.

The two sides "negotiated and exchanged opinions with the emphasis on the official resumption of bilateral relations and the executive steps towards the reopening of the embassies and consulates of the two countries", Iran's foreign ministry said in a statement.

Saudi state TV channel Al Ekhbariya aired footage of the pair of diplomats shaking hands in front of Saudi and Iranian flags and then talking and smiling.

Chinese foreign ministry spokesperson Mao Ning hailed the meeting, adding that the ministers "expressed their gratitude to China for its contribution to the promotion of dialogue".

Under last month's agreement, the two countries are to reopen their embassies and missions within two months and implement security and economic cooperation deals signed more than 20 years ago.

Talks between the foreign ministers are expected to be followed by Iranian President Ebrahim Raisi's visit to Riyadh. 

Raisi accepted an invitation from Saudi Arabia's King Salman, Iran's First Vice President Mohammad Mokhber said on Monday.

- Challenge to US -

Iran and Saudi Arabia support rival sides in several conflict zones across the region, including in Yemen, where Huthi rebels are backed by Tehran and Riyadh leads a military coalition supporting the government. 

The two sides also vie for influence in Syria, Lebanon and Iraq.

Riyadh's traditional ally Washington welcomed the detente agreement but said it remains to be seen whether the Iranians will "honour their side of the deal".

China's success in bringing Iran and Saudi Arabia together has challenged the United States' long-standing role as the main outside power broker in the Middle East.

An expert told AFP that Beijing's role would likely increase confidence that any deal would stick.

"Because China is a strong backer of Iran, Saudi should have more confidence in Iran's ability to comply with the agreement, an issue that has always been in doubt," said Joel Rubin, former US Deputy Assistant Secretary of State for Legislative Affairs.

Thursday's meeting "suggests that the process hasn't gone off track since the Beijing announcement last month", said Ali Vaez, Director of  the International Crisis Group's Iran Project.

"But it's still early days to judge whether this is just a tactical detente or a way-station towards strategic rapprochement."

- Warming ties -

Officials from Iran and Saudi Arabia held several rounds of dialogue in Baghdad and Oman before they met in Beijing.

In 2016 several Gulf countries followed Riyadh's action in scaling back ties with Tehran, but they have led the way in restoring diplomatic relations.

Iran welcomed an Emirati ambassador last September, after a six-year absence, and on Wednesday named its own ambassador to the UAE following a nearly eight-year hiatus.

It said last year Kuwait had sent its first ambassador to Tehran since 2016.

Iran has also welcomed a potential rapprochement with Bahrain, a close Saudi ally, which in the past accused Iran of backing a Shiite-led uprising in the Sunni-ruled kingdom, an accusation Tehran denies.