* Militias claiming loyalty to retired general attacked parliament on Sunday
* General Haftar rebelled against Gaddafi in the 1980s
* Violence could be attempt to form united front against Islamists
* Western governments fear chaos in Libya could spread to neighbors
ALGIERS/TRIPOLI, May 20 (Reuters) - When a dispute erupted over dissolving Libya's parliament last February, a former general dressed in full army uniform made a surprise television broadcast calling on the military to "rescue" the country.
Flanked by a Libyan flag and a large map, retired Major General Khalifa Haftar demanded a caretaker government take over from a parliament paralyzed by rivalries after the 2011 war that ended Muammar Gaddafi's rule.
Quickly, rumors of troop movements fed coup fears. But no tanks rolled into the streets, and many dismissed Haftar as a would-be putschist.
Libyans already knew the grey-haired ex-officer who first rebelled against Gaddafi in the 1980s. Now he is back center-stage after groups of militias claiming loyalty to him attacked parliament in Tripoli on Sunday and assaulted Benghazi to clear out Islamist militants.
Two regular military units have already backed Haftar's self-declared Libyan National Army, making him one more player in an emerging confrontation between rival brigades of former anti-Gaddafi rebels who are Libya's real powerbrokers.
With Libya's new army still in training, two loose confederacies of ex-fighters are lined up with Islamist and anti-Islamist political forces and locked in an uneasy balance of power where neither is able to overcome the other.
Haftar's movement and the violence in Tripoli and Benghazi may signal an attempt to draw up a broader anti-Islamist front that risks a wider-scale battle over the North African OPEC state still struggling to shape its fragile democracy.
"Politically we are in limbo until things become clearer. Both in Benghazi and Tripoli, security is very fragile," one Western diplomat said. "I question how coordinated it was between Haftar and others, but they have common interests. It may be a marriage of convenience."
On one side, the Zintanis, in the western mountains, and their allied Qaaqaa and Sawaiq brigades in Tripoli, are fiercely anti-Islamist and back the National Forces Alliance, a coalition of nationalist parties led by an ex-Gaddafi official.
Lined up broadly against them are the Misratan brigades, based in the port city of Misrata, who are Islamist-leaning and support the political wing of the Muslim Brotherhood, along with other Islamist brigades and their allies.
The potential for more widespread confrontation was apparent on Sunday when gunmen with anti-aircraft cannons attacked parliament, triggering skirmishes across Tripoli among regular forces, and pro- and anti-Islamist factions.
It is not clear if Haftar forces were even involved in the Tripoli clashes, though one of his allies, Brigadier-General Saqer Al-Joroushi, claimed Haftar's troops worked with the Qaaqaa and Sawaiq brigades.
The two groups did not confirm any role. But officials and diplomats said Tripoli's violence may have been a Qaaqaa attempt to thwart Prime Minister Ahmed Maiteeq, who got backing by the Muslim Brotherhood and is seen by critics as pro-Islamist.
He had just submitted his cabinet names to the parliament on Sunday when gunmen attacked. After the assault, it was not even clear whether Maiteeq would be able to get lawmakers to hold a session to approve his government.
"Tripoli cannot become a battleground for political disputes," Tripoli local council said in a statement. "We hold the local Qaaqaa brigade responsible for the violence."
ONE AMONG MANY
Since the NATO-backed war against Gaddafi, Western powers have struggled to help a fragile Libyan government gain a secure footing, with growing international concern as Libya's instability threatens to spill across to its neighbors.
Algeria's government last week sent special forces into Tripoli to evacuate its ambassador and closed down its embassy after what sources said was an al Qaeda threat.
The United States has temporarily moved about 250 Marines and a number of aircraft to Sicily from Spain as a precaution due to concerns about unrest, bolstering the U.S. ability to evacuate its citizens in any crisis.
"We're obviously watching the situation very closely as the unrest continues to worsen," a U.S. defense official said on condition of anonymity. "We're posturing as best we can; we're watching as best we can."
Complicating Libya's security, thousands of militia fighters have semi-official status on the government payroll and are linked to the ministries of defense and interior in an attempt bid to co-opt them into loyalty to the state.
How much support Haftar can gain in the country's fledgling armed forces or, more importantly, among the network of rebels is difficult to judge in a country where alliances run across tribal, regional and political lines.
But he has a long pedigree as a rebel commander. A former Gaddafi ally, he joined Libya's former leader in a 1969 coup that bought the autocrat to power. But he later fell out with Gaddafi over the country's war in Chad in 1980s.
According to a report on Haftar by U.S. think-tank The Jamestown Foundation, he also had past backing from the U.S. Central Intelligence Agency. He spent 20 years in the United States before returning to lead rebels in 2011.
Since his February statement, diplomats said Haftar had campaigned, mainly in eastern Libya, reaching out to tribes and militias to drum up support for his position.
At least in Benghazi, the regular air force appeared to join his troops with helicopters attacking Islamist bases there. An air force unit in Tobruk on Monday pledged support and, more significantly, a special forces brigade chief also backed him.
Support in the east is less surprising. His attacks in Benghazi mostly targeted Islamists like Ansar al Sharia - blamed for leading an assault on the U.S. consulate in the city in 2012 when ambassador Christopher Stevens and three other Americans died, and branded a terrorist organization by Washington.
Many Benghazi residents and troops there are frustrated at the lack of support to halt assassinations and bombings in the city where militants often openly operate their checkpoints.
Some Haftar backers are even drawing comparisons to Egypt's former army chief Abdel Fattah al-Sisi, who removed the Muslim Brotherhood from power and is now frontrunner in the country's presidential elections next week.
"Haftar is probably positioning himself as a strongman. Lots of Libyans are saying they need that," one diplomat said. "He is saying all the right things."
INSTABILITY TO COME?
One key factor will the support of Ibrahim Jathran, the former anti-Gaddafi rebel who has taken over oil ports since last summer in an attempt to force Tripoli to give more federal rights to self-declared eastern Cyrenica region.
He had agreed with Maiteeq's predecessor to steadily lift his blockade of four key ports and help bring Libya's battered oil shipments back to normal. But Jathran has since rejected the new premier, suspended his deal and backed Haftar.
"The latest events are potentially a watershed; Haftar is trying to put together a loose coalition of forces, including the Zintanis and Jathran's federalists, to counter the power of the Islamist camp," said Riccardo Fabiani at Eurasia Group.
"For the first time, there are potentially two blocs, instead of the fragmentation that we have seen before and has been the main reason why Libya has not descended into chaos."
But any attempt to bring together an anti-Islamist alliance with overwhelming force will meet not only political resistance, but also fierce opposition from Misrata and allied brigades, who will react to any attempt by their Zintani rivals to make gains, especially in Tripoli.
Late last year, most major militias moved out of their bases in the capital after clashes killed dozens. The next step may be an attempt to reposition themselves in Tripoli.
Misratans had made up the bulk of the so-called Libya Shields force created by the parliament chief to help security in Tripoli, where many residents blame unruly Bedouin elements from Zintan for crime and kidnappings.
Other Islamist brigades are already making noises. The Operations Room for Libya's Revolutionaries, accused of kidnapping the prime minister last year, say rivals are trying to reinstall a dictatorship in Libya.
So far the Misratan brigades have stayed out of the fray.
But parliament speaker, Nuri Abu Sahmain, who is also military commander in chief, asked Misrata's Libya Shield forces to move to Tripoli to protect government institutions, according to a statement on an official army webpage.
"Now we have to see how the Misratans react," said another diplomat in Tripoli. "We have been waiting for three years for this to crystallize. It could get worse a lot quicker."
(Additional reporting by Ahmed Elumami; Editing by Will Waterman)