DUBAI, UNITED ARAB EMIRATES -- Iran and Saudi Arabia agreed Friday to reestablish diplomatic relations and reopen embassies after seven years of tensions. The major diplomatic breakthrough negotiated with China lowers the chance of armed conflict between the Mideast rivals -- both directly and in proxy conflicts around the region.

The deal, struck in Beijing this week amid its ceremonial National People's Congress, represents a major diplomatic victory for the Chinese as Gulf Arab states perceive the United States slowly withdrawing from the wider Middle East. It also comes as diplomats have been trying to end a long war in Yemen, a conflict in which both Iran and Saudi Arabia are deeply entrenched.

The two countries released a joint communique on the deal with China, which brokered the agreement as President Xi Jinping was awarded a third five-year term as leader earlier Friday.

Xi, whose administration in recent days has relaunched a campaign to challenge the U.S.-led Western liberal order with warnings of "conflict and confrontation," was credited in a trilateral statement with facilitating the talks through a "noble initiative" and having personally agreed to sponsor the negotiations that lasted from Monday through Friday.

That reflects China's desire to earn goodwill to aid its international economic and political ambitions, and Wang was quoted by state media saying that as a "good-faith and reliable mediator, China has faithfully fulfilled its duties as the host."

"We will continue to play a constructive role in properly handling hotspot issues in today's world in accordance with the wishes of all countries and demonstrate our responsibility as a major nation," Wang said.

Videos on Iranian state media showed Ali Shamkhani, the secretary of Iran's Supreme National Security Council, with Saudi national security adviser Musaad bin Mohammed al-Aiban and Wang Yi, China's most senior diplomat.

The joint statement calls for reestablishing ties and reopening embassies to happen "within a maximum period of two months." A meeting by their foreign ministers is also planned.

In the video, Wang could be heard offering "wholehearted congratulations" on the two countries' "wisdom."

"Both sides have displayed sincerity," he said. "China fully supports this agreement."

The United Nations welcomed the Saudi-Iranian rapprochement and thanked China for its role. "Good neighborly relations between Iran and Saudi Arabia are essential for the stability of the Gulf region," UN spokesperson Stephane Dujarric said at UN headquarters.

The U.S. also welcomed "any efforts to help end the war in Yemen and de-escalate tensions in the Middle East region," White House press secretary Karine Jean-Pierre said.

China, which last month hosted Iran's hard-line President Ebrahim Raisi, is also a top purchaser of Saudi oil. Xi visited Riyadh in December for meetings with oil-rich Gulf Arab nations crucial to China's energy supplies.

Iran's state-run IRNA news agency quoted Shamkhani as calling the talks "clear, transparent, comprehensive and constructive."

"Removing misunderstandings and the future-oriented views in relations between Tehran and Riyadh will definitely lead to improving regional stability and security, as well as increasing cooperation among Persian Gulf nations and the world of Islam for managing current challenges," Shamkhani said.

Al-Aiban thanked Iraq and Oman for mediating between Iran and the kingdom, according to his remarks carried by the state-run Saudi Press Agency.

"While we value what we have reached, we hope that we will continue to continue the constructive dialogue," the Saudi official said.

Tensions long have been high between Iran and Saudi Arabia. The kingdom broke ties with Iran in 2016 after protesters invaded Saudi diplomatic posts there. Saudi Arabia had executed a prominent Shiite cleric with 46 others days earlier, triggering the demonstrations.

That came as Crown Prince Mohammed bin Salman, then a deputy, began his rise to power. The son of King Salman, Prince Mohammed previously compared Iran's Supreme Leader Ayatollah Ali Khamenei to Nazi Germany's Adolf Hitler, and threatened to strike Iran.

Since then, the U.S. unilaterally withdrew from Iran's nuclear deal with world powers in 2018. Iran has been blamed for a series of attacks after that, including one targeting the heart of Saudi Arabia's oil industry in 2019, temporarily halving the kingdom's crude production.

Though Yemen's Iranian-backed Houthi rebels initially claimed the attack, Western nations and experts blamed Tehran. Iran denied it and also denied carrying out other assaults later attributed to the Islamic Republic.

Religion also plays a key role in their relations. Saudi Arabia, home to the cube-shaped Kaaba that Muslims pray toward five times a day, has portrayed itself as the world's leading Sunni nation. Iran's theocracy, meanwhile, views itself as the protector of Islam's Shiite minority.

The two powerhouses have competing interests elsewhere, such as in the turmoil in Lebanon and in the rebuilding of Iraq following the U.S.-led 2003 invasion that toppled Saddam Hussein.

The leader of the Iranian-backed Lebanese militia and political group Hezbollah, Hassan Nasrallah, said the agreement could "open new horizons" in Lebanon, Syria and Yemen. Iraq, Oman and the United Arab Emirates also praised the accord.

Top Pakistani diplomat Bilawal Bhutto Zardari, chair of the Organization of Islamic Cooperation's Council of Foreign Ministers, praised China for "encouraging dispute resolution, rather than on encouraging perpetual disputes."

Kristian Coates Ulrichsen, a research fellow at Rice University's Baker Institute who long has studied the region, said Saudi Arabia reaching the deal with Iran came after the United Arab Emirates reached a similar understanding with Tehran.

"This dialing down of tensions and de-escalation has been underway for three years and this was triggered by Saudi acknowledgement in their view that without unconditional U.S. backing they were unable to project power vis-a-vis Iran and the rest of the region," he said.

Prince Mohammed, focused on massive construction projects at home, likely wants to pull out of the Yemen war as well, Ulrichsen added.

"Instability could do a lot of damage to his plans," he said.

The Houthis seized Yemen's capital, Sanaa, in 2014 and forced the internationally recognized government into exile in Saudi Arabia. A Saudi-led coalition armed with U.S. weaponry and intelligence entered the war on the side of Yemen's exiled government in 2015. Years of inconclusive fighting created a humanitarian disaster and pushed the Arab world's poorest nation to the brink of famine.

A six-month cease-fire, the longest of the Yemen conflict, expired in October.

Negotiations have been ongoing recently, including in Oman, a longtime interlocutor between Iran and the U.S. Some have hoped for an agreement ahead of the Muslim fasting month of Ramadan, which begins later in March. Iran and Saudi Arabia have held intermittent talks in recent years but it wasn't clear if Yemen was the impetus for this new detente.

Yemeni rebel spokesman Mohamed Abdulsalam appeared to welcome the deal in a statement that also slammed the U.S. and Israel. "The region needs the return of normal relations between its countries, through which the Islamic society can regain its lost security as a result of the foreign interventions, led by the Zionists and Americans,鈥 he said.

For Israel, which has wanted to normalize relations with Saudi Arabia despite the Palestinians remaining without a state of their own, Riyadh easing tensions with Iran could complicate its own regional calculations.

The government of Israeli Prime Minister Benjamin Netanyahu offered no immediate comment Friday. Netanyahu, under pressure politically at home, has threatened military action against Iran's nuclear program as it enriches closer than ever to weapons-grade levels. Riyadh seeking peace with Tehran takes one potential ally for a strike off the table.

It was unclear what this development meant for Washington. Though long viewed as guaranteeing Mideast energy security, regional leaders have grown increasingly wary of U.S. intentions after its chaotic 2021 withdrawal from Afghanistan.

But the White House bristled at the notion a Saudi-Iran agreement in Beijing suggests a rise of Chinese influence in the Mideast. "I would stridently push back on this idea that we're stepping back in the Middle East -- far from it," National Security Council spokesman John Kirby said.

Mark Dubowitz, head of the Foundation for the Defense of Democracies, which opposes the Iran nuclear deal, said renewed Iran-Saudi ties via Chinese mediation "is a lose, lose, lose for American interests," noting: "Beijing adores a vacuum."

But Trita Parsi of the Quincy Institute, which advocates engagement with Iran and supports the nuclear deal, called it "good news for the Middle East, since Saudi-Iranian tensions have been a driver of instability." He added that "China has emerged as a player that can resolve disputes rather than merely sell weapons to the conflicting parties," noting a more stable Middle East also benefits the U.S.

------

Associated Press writers Nasser Karimi in Tehran, Iran, Jack Jeffery in Cairo, Aamer Mahdani, Darlene Superville and Matthew Lee in Washington, Jennifer Peltz in New York and Bassem Mroue and Abby Sewell in Beirut contributed.