CAIRO — A power struggle between Yemen’s government and southern separatists threatened to fracture a Saudi-led coalition battling northern rebels in Yemen. But on Tuesday, the warring sides signed an agreement in the Saudi capital of Riyadh to end their animosities.

The deal was hailed by the Saudi government and Western powers as paving the way to finding a broader political solution to end Yemen’s nearly five-year-long civil war.

In a televised signing ceremony in Riyadh, Saudi Crown Prince Mohammed bin Salman said that “this agreement will open, God willing, broader talks between Yemeni parties to reach a political solution and end the war.”

The U.N. envoy to Yemen, Martin Griffiths, said in a statement that the agreement is “an important step for our collective efforts to advance a peaceful settlement to the conflict in Yemen.”

Some Yemen observers expressed caution, noting that other agreements between warring factions in the country have struggled to take root on the ground.

“The big question is: how easy will it be to implement fully?” Elisabeth Kendall, a Yemen expert at Oxford University, asked in a tweet.

The war in Yemen pits a coalition of regional Sunni Muslim powers, led by Saudi Arabia and the United Arab Emirates, against Shiite rebels known as the Houthis who are aligned with Iran. The coalition is ostensibly seeking to restore Yemen’s government, which was ousted by the Houthis.

The conflict worsened a humanitarian crisis that has left millions of Yemenis on the brink of famine. More than 100,000 people have died since 2015, including more than 12,000 civilians in direct attacks, according to a report last week by the Armed Conflict Location and Event Data Project, a nonprofit group monitoring war casualties.

Within the coalition, tensions have been growing. Separatists belonging to the Southern Transitional Council have long held grievances against northerners who have dominated Yemen’s government for decades. The southerners seek self-rule as well as a place in a future government.

Backed by the UAE, the separatists are also deeply suspicious of Islamists who hold key positions in the government led by President Abed Rabbo Mansour Hadi. In August, the separatists seized control of the government’s interim capital in the southern port city of Aden and swiftly started to gain control over other areas of Yemen’s south.

According to Saudi Arabia’s official news agencies, Tuesday’s deal calls for the return of the Hadi government to Aden within seven days. It also calls for the placing of tens of thousands of troops, including separatist forces, under the control of the government. The government will be reshuffled to be made up equally of northerners and southerners.

Kendall said the agreement, if implemented, would reduce imminent risk of a north-south war in Yemen and would mark a new phase of cooperation between the southerners and the Saudi coalition. It would also focus coalition members’ efforts on battling the Houthis — not each other.

Griffiths said in his statement, “Listening to southern stakeholders is important to the political efforts to achieve peace in the country.”

Kareem Fahim in Istanbul contributed to this report.

Correction: An earlier version of this report said the deal was signed Monday. It was signed Tuesday.