Saudi Arabia and Iran have agreed to resume diplomatic ties and reopen embassies, they said in a joint statement carried by the Saudi state news agency SPA.
The agreement was reached after talks in Beijing between top security officials from the two countries.
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."
They 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.
President Donald Trump said talks with Iran to end the war could soon resume and end in a deal, telling the world to watch out for an "amazing two days", while US forces imposing a blockade turned back vessels leaving Iranian ports.
A student shot at least four people dead including fellow pupils and wounded at least 20 others at a middle school in southeastern Turkey on Wednesday, the local governor said, marking the country's second school attack in two days.
At least 17 people died and 36 others were injured following a suspected boiler explosion at a power plant operated by India's Vedanta Ltd in the central Indian state of Chhattisgarh, a government official said on Wednesday.
US Secretary of State Marco Rubio hosted a rare meeting between Israeli and Lebanese envoys in Washington on Tuesday, saying he hoped the two countries would agree to a framework for a peace process, even as Israel pressed its war on Hezbollah.
Negotiating teams from the US and Iran could return to Islamabad this week to resume talks to end the war, sources told Reuters on Tuesday, after the collapse of weekend negotiations prompted Washington to impose a blockade on Iranian ports.