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.
One of Afghanistan's worst earthquakes killed more than 800 people and injured at least 2,800, authorities said on Monday, as helicopters ferried the wounded to hospital after they were plucked from the rubble of homes being combed for survivors.
Israel pushed tanks deeper into Gaza City and detonated explosives-laden vehicles in one suburb as airstrikes killed at least 19 people on Monday, Palestinian officials and witnesses said.
India's Narendra Modi told Vladimir Putin on Monday that India and Russia stood shoulder to shoulder even in difficult times after the Kremlin chief cast the Indian prime minister as his "dear friend" and gave him a lift in his armoured limousine.
Chinese President Xi Jinping urged leaders to leverage their "mega-scale market", while Russian President Vladimir Putin showed support for Xi's ambition for a new global security and economic order that poses a challenge to the US during a regional summit on Monday.
South Korea has suspended a military radio broadcast that transmits to North Korea as part of measures aimed at easing tensions with Pyongyang, Seoul's defence ministry said on Monday.