Iran and Saudi Arabia agreed on Friday to re-establish relations after seven years of hostility which had threatened stability and security in the Gulf.

The deal was announced after four days of previously undisclosed talks in Beijing between top security officials from the two Middle East powers.

Tehran and Riyadh agreed "to resume diplomatic relations between them and re-open their embassies and missions within a period not exceeding two months", according to a statement issued by Iran, Saudi Arabia and China.

"The agreement includes their affirmation of the respect for the sovereignty of states and the non-interference in internal affairs."

In Friday's agreement, Saudi Arabia and Iran also agreed to activate a security cooperation agreement signed in 2001, as well as another earlier accord on trade, economy and investment.

Both countries thanked China, as well as Iraq and Oman for hosting earlier talks in 2021 and 2022.

The agreement was signed by Iran's top security official, Ali Shamkhani, and Saudi Arabia's national security adviser Musaed bin Mohammed Al-Aiban.

China's foreign ministry did not immediately respond to a request for comment.

A White House national security spokesperson said the United States was aware of reports of the agreement and welcomed any efforts to help end war in Yemen and de-escalate tensions in the Middle East.

"MOVING IN RIGHT DIRECTION"

Iran’s Foreign Minister Hossein Amirabdollahian said that normalising relations offered great prospects for both countries and for the Middle East, and hinted at further steps.

"The neighbourhood policy, as the key axis of the Iranian government’s foreign policy, is strongly moving in the right direction and the diplomatic apparatus is actively behind the preparation of more regional steps," Amirabdollahian tweeted.

A senior Iranian security official said Friday's agreement had been endorsed by Supreme Leader Ayatollah Ali Khamenei.

"That is why Shamkhani travelled to China as the supreme leader’s representative,” the official told Reuters.

“The establishment wanted to show that the top authority in Iran backed this decision.”

(Reporting by Dubai newsroom; Writing by Dominic Evans; editing by Jason Neely, Jon Boyle and Nick Macfie)