ALGIERS/TRIPOLI (Reuters) - Fresh from a Rome summit on Libya's crisis, American, European and U.N. officials are confidently backing a proposed peace deal between the country's warring factions to end chaos that has allowed Islamic State to flourish.
Libyan delegates from different groups plan to sign up on Wednesday to the agreement to form a unity government and seek a ceasefire - a decision Western powers hope will create the momentum to pull recalcitrant opponents along.
But if world leaders needed an indication of the multiple challenges to implementing a deal on the ground, they need only look at security arrangements in the capital Tripoli to see how complex it could become.
With Libya having no real national army, at least seven armed brigades are entrenched in the city, under semi-official control of the defense or interior ministries, some supporting the U.N. accord, others allied to political leaders opposing it.
More broadly, two rival Libyan governments - one based in Tripoli and the other in Tobruk to the east - are backed by coalitions of former rebels who fought together against Muammar Gaddafi in 2011 but whose ranks are now fragmented along tribal, regional and political lines.
Their loyalties often lie more with their commanders than with a state that pays salaries to both sides in an attempt to keep them in check even as they battle for control of the OPEC nation and the oil wealth that drives its economy.
In Rome, U.S. Secretary of State John Kerry joined European and North African leaders at the weekend in promising aid and called for an immediate ceasefire. They said they hoped a majority of both parliaments would sign up to the deal and others could join later. But economic and travel sanctions could also be in the works for those who resist.
"The doors are always open to those who still oppose the agreement. But those who continue to obstruct should be held accountable," U.N. envoy Martin Kobler said.
Western officials now hope war fatigue, the growing drain on Libya's economy and oil revenues, the promise of international aid and the common threat of Islamic State will help coax as broad a backing as possible for a new government.
"Things can go wrong, it's possible that it won't work, it's possible it won't happen, but we think it will happen and that it will work," said a senior U.S. State Department official.
Moderates from both the General National Congress (GNC) in Tripoli and the House of Representatives in the east are expected to back the deal, as well as independents and local leaders. But each 200-member house has a number of lawmakers who have boycotted their chambers since their election, making judging a majority difficult.
Just how much support the U.N. accord has on the ground is in question after factions within both parliaments and governments rejected it as illegitimate and announced their own proposal. The speakers of both assemblies have also resisted, while other lawmakers are holding out for more amendments.
"We did not reject the U.N. draft, but we have our reservations," said GNC lawmaker Mousa Faraj. "We want to demystify some of the articles in the draft, so we can sign."
Still, analysts question how much control those inside a new government will have over the men with guns and the hardliners who have quickly turned to a show of armed force in the past to stymie political decisions.
"The government of national unity will probably be weak, with severe political challenges from hardliners and almost impossible challenges from the ground, starting with the humanitarian crisis and the looming fiscal collapse," said Mattia Toaldo, at the European Council on Foreign Relations.
Since 2011, former rebel brigades backing competing political factions have repeatedly stormed ministries in Tripoli, attacked the parliament and even briefly abducted a prime minister, actions all taken in the name of revolutionary legitimacy.
Rival groups armed with jeeps mounted with anti-aircraft cannons and rocket-propelled grenades clashed in street battles, sometimes over personal feuds.
But since last year, the capital has been controlled by an armed faction called Libya Dawn, an alliance of former rebel brigades from the powerful port city of Misrata and Tripoli brigades, including some more Islamist-leaning factions.
This has created an uneasy mix of armed groups including those close to political opponents of the U.N. deal and some units whose commanders back the peace agreement.
Misrata brigades have said they would be ready to protect the new government. Spokesmen for two Tripoli brigades said they were not involved in political decisions, but supported dialogue.
"We don't know how various militias will respond and whether they will allow the government to set up in Tripoli," said one Western diplomat.
Even if a new government is established, the process of forging a ceasefire and securing cooperation among the more powerful armed factions to build a new Libyan army will be complicated.
Major forces in the country include the so-called Libyan National Army, led by General Khalifa Haftar, a former Gaddafi ally who has been named commander-in-chief of the eastern government and has led his own campaign against Islamist militants in Benghazi.
He is hated by forces in Misrata and Tripoli, who see him as a remnant of the Gaddafi era. His spokesman said his forces were not involved in politics, only in fighting terrorism.
Ibrahim Jathran, a federalist who has in the past pushed for more autonomy for his local region, controls two major oil ports with his Oil Facility Guards. His spokesman said he backed the U.N. deal, and supported the eastern government.
Jathran's forces clashed before with Misrata brigades when they tried to retake eastern oil ports from him a year ago. But they have since had an informal truce with Misrata groups more focused on containing Islamic State forces in nearby Sirte.
Western officials said the first step towards stability would be to establish a unity government in Tripoli, before moving on to building a national military to protect Libya.
"That's going to take time," the State Department official said. "It's going to require a lot of political wheeling and dealing within Libya, and steady, calm support from the outside."
Additional reporting by Ayman Al-Warfalli in Benghazi; Editing by Pravin Char