* Chaotic attack on parliament, clashes in Tripoli
* Forces loyal to former general demand GNC hand over power
* Attack comes after clashes in eastern city Benghazi (Adds details from minister, from oil protests, and context)
By Ahmed Elumami and Ulf Laessing
TRIPOLI, May 18 (Reuters) - Heavily armed gunmen stormed Libya's parliament on Sunday demanding its suspension and claiming loyalty to a renegade army general who has vowed to purge the country of Islamist militants.
Smoke rose over parliament after gunmen attacked and then withdrew, and gunfire erupted across Tripoli, where rival militias clashed in some of the worst violence in the city since the end the 2011 war against Muammar Gaddafi.
Details of who was involved Sunday's chaotic attack were unclear, but loyalists of retired General Khalifa Haftar said his forces and militia allies had planned the parliament assault in a campaign to rid Libya of Islamist hardliners.
Any alliance of militias lining up against Islamist groups threatens to deepen chaos in the OPEC oil producer where a fragile government already struggles to gain legitimacy and impose authority over brigades of former fighters.
"We announce the freezing of the GNC," said Colonel Mukhtar Fernana, a former military police officer from the Zintan region, reading out a statement on al-Ahrar TV.
Haftar's spokesman Mohamed al-Hejazi said Fernana's group was allied to the former general.
Fernana said their movement was not a coup, but said the parliament had no legitimacy and should hand over power to a 60-member body that was recently elected to rewrite Libya's constitution.
It was not immediately clear how much backing Haftar's men had within Libya's nascent regular armed forces and the country's powerful brigades of former rebels or whether the parliament was fully under government control after the attack.
Justice Minister Saleh al-Mergani condemned the assault on parliament and rejected the group's demands.
"The government demands an immediate stop to military action and use of force to express political opinion," he told a news conference calling for dialogue.
Witnesses said armed local residents were blocking roads to the parliament building after the attack, but their identities and affiliation were not clear.
The attackers kidnapped about 10 employees from the GNC, an official said. At least two people were killed and another 55 wounded in the violence, officials said.
Haftar, once a Gaddafi ally who turned against him over a 1980s war in Chad, fueled rumours of a coup in February when he appeared on television in uniform calling for a caretaker government to end Libya's crisis.
Since the end of Gaddafi's one-man rule, militias of ex-rebels have become de-facto powerbrokers in the vacuum of Libya's political chaos, carving out fiefdoms and exercising their military muscle to make demands on the state.
But the most powerful, heavily armed brigades are rivals - the Zintans and the Misratans - loosely allied with competing political factions battling to define what kind of state Libya should become three years after Gaddafi's fall.
Compounding the chaos, another former rebel commander, Ibrahim Jathran, who occupied eastern oil ports last summer, said he supported suspending parliament and handing over legislative power to the constitutional-drafting body.
His protest to demand more federal autonomy and a greater share of oil wealth for his eastern region has helped cut Libya's crude output to around 200,000 barrels per day from 1.4 million bpd before the summer.
Gunfire and explosions could still be heard until late at night on the airport road which is controlled by a brigade from Zintan, a staunchly anti-Islamist force.
Libyan news websites said forces from Zintan had initially stormed the parliament and then retreated to the airport road, but there was no confirmation from Zintan or the anti-Islamist Qaaqaa brigade about their involvement.
On Saturday, parliamentary speaker and military commander-in-chief Nuri Abu Sahmain accused Haftar of trying to stage a coup. Several reports said Sahmain had been kidnapped after Sunday's attack, but he denied that.
Haftar had already sent his fighters into Benghazi on Friday against Islamist militants based there, claiming Libya's government had failed to halt violence in the eastern city.
At least 40 people were killed in those clashes, which involved some air force helicopters.
In Benghazi, the cradle of the uprising against Gaddafi, authorities have struggled to curb violence and stem attacks blamed on Ansar al-Sharia, an Islamist group that Washington labels as a terrorist organisation.
Clashes broke out in two areas of Benghazi on Sunday night between Haftar's forces and Islamist militants, and unknown attackers fired Grad rockets at the city's airport, a security source said. There was no immediate report of casualties.
After Gaddafi, Libya's fragile democracy has hobbled from crisis to crisis with the country on its third prime minister since March, its new constitution unwritten and its parliament caught up in constant infighting.
The parliament has been paralyzed by rivalries between the Islamists tied to Egypt's Muslim Brotherhood and a nationalist movement, leaving many Libyans frustrated over lack of progress since the war.
Many former rebel fighters have been put on the government payroll to provide security to ministries and offices, but they often remain more loyal to commanders, political allies or their regional tribes than the state. (Additional reporting by reporting Feras Bosalum; Writing by Patrick Markey; Editing by Rosalind Russell, Bernard Orr and Eric Walsh)