Crisis escalates as rival governments preside over violence that is tearing nation apart three years after Arab spring

When Libya threw off the shackles of dictatorship in its Arab spring revolution, few could have imagined that, three years later, it would have two rival governments installed at opposite ends of the country, presiding over fighting that has, in effect, torn the nation in two.

In the capital, Tripoli, an Islamist-dominated congress where less than half the members show up to vote has appointed Ahmed Maiteeq as the third prime minister in four months.

But the man he wants to replace, Abdullah al-Thinni, insists that he is still the rightful prime minister. Al-Thinni, who condemned his rival's appointment as illegal, has now decamped to the oil-rich eastern province of Cyrenaica with his cabinet and sections of that same congress.

Al-Thinni is now in talks with army officers allied to the renegade general Khalifa Haftar, whose forces have for three weeks battled Islamist militias that he labels "terrorists".

Government, in the sense of a joined-up administration, has all but collapsed and mediation efforts appear stillborn.

Many had hoped the country's supreme court would end the standoff by ruling on Thursday on the legality of Maiteeq's election. But judges appeared to duck the issue, putting off the decision until next week. Whether a ruling will make a difference amid the spiralling violence is unclear.

What is clear is that Libya's democratic dream has all but collapsed, in a week that has seen authoritarian rulers claiming mandates after elections of questionable credibility in fellow Arab spring states Egypt and Syria.

The crisis began last month when Haftar, supported by sections of the armed forces, launched Operation Restore Libyan Dignity in Cyrenaica's capital, Benghazi, with assaults on Islamist militias. The city is now a war zone, with daily battles between militias and army formations. TV footage this week showed air force helicopter gunships firing relays of missiles into militia bases, with streets deserted and civilians cowering in their homes during fighting that has cost more than 100 lives. Haftar himself survived a suicide car bomb that killed four soldiers at his headquarters.

For some, it is an echo of the 2011 Arab spring uprising, in which rebels, backed by Nato air strikes, toppled the government of Muammar Gaddafi in an eight-month civil war.

Yet the faultlines have changed, with the former rebel coastal city of Misrata aligned with what remains of congress and Haftar supported by powerful Zintan militias in mountains west of the capital.

Islamists insist they control a democratic congress, voted into power in the country's first post-revolution elections, but opponents say the parliament lost its legitimacy by extending its mandate beyond its original limit in February.

As fighting worsens, foreign officials have become targets. The International Committee of the Red Cross on Thursday suspended operations after a Swiss employee was shot dead in the coastal city of Sirte, and a UN spokesman said four of its diplomats were captured and "roughed up" by militias at Tripoli airport.

The United States has moved warships, aircraft and 1,000 marines to the region and Washington has joined Canada, Jordan and Tunisia in advising citizens to leave Libya immediately.

Many Libyans are wary of Haftar, an ally of Gaddafi before defecting to join US-backed dissidents, but hope the support he has in the regular army means an end to three years of anarchy.

"The support for Haftar is in essence support for institutions, not for individuals," said Libyan journalist Mohamed Eljarh. "There is this movement in eastern Libya which has managed to bring lots of actors together."Haftar's campaign has also received what some have interpreted as partial support from Washington, which is concerned about the rise of jihadists in Libya. America's ambassador to the country, Deborah Jones, has said: "It's not necessarily for me to condemn [Haftar's] actions in going against very specific [terrorist] groups."

Ansar al-Sharia, the Benghazi militia the US blames for killing its ambassador in the city in 2012, has borne the brunt of Haftar's attacks, and it has warned Washington it risks a "bloodbath" if it intervenes militarily.

Outside powers may prove crucial in the standoff, with Al-Thinni's ministers apparently winning support this week in meetings with Egypt's president-elect, Abdel Fatah al-Sisi, who warned Cairo would not tolerate "terrorist activities" launched from Libya.