Updated

Members of Libya's rival parliaments have signed a U.N.-sponsored deal on forming a unity government, aiming to bring peace to the war-ravaged country.

Supporters of the agreement hope that rival political factions and militias will embrace the deal and agree on a cease-fire, so that they can fend off the Islamic State extremist group, which is expanding its gains in the country.

Libya slid into chaos following the 2011 toppling and killing of dictator Moammar Gadhafi. Since then, it has been torn between an internationally recognized government, based in the east, and an Islamist-backed government in the capital, Tripoli.

It also faces threats from IS extremists.

But the agreement, signed in Morocco on Thursday, has detractors on both sides who seek a separate deal without U.N. involvement.