By Ghaith Shennib and Jessica Donati
TRIPOLI (Reuters) - Libya's parliament voted on Sunday to ban anyone who held a senior position during Muammar Gaddafi's 42-year rule from government, a move which could unseat the prime minister and other top officials regardless of their part in toppling the dictator.
Politicians debated the draft law for months, but the issue came to a head this week when heavily armed groups took control of two ministries and stormed other institutions including the state broadcaster.
The decision to hold the vote under duress could embolden the armed groups to use force again to assert their will over parliament.
Prime Minister Ali Zeidan, a diplomat under Gaddafi who defected to the exiled opposition in 1980, could be among those barred from office, although this remained unclear and a parliament spokesman said it would be decided by a committee charged with implementing the law.
"Being unjust to a few is better than defeating the whole objective of the law," said one of the hundreds who filled Tripoli's main square to celebrating the passage of the law, many of them shooting guns into the air.
Nearly two years after Gaddafi was overthrown, the gunmen who fought to end his 42-year dictatorship are refusing to lay down their arms and go back to civilian life - militiamen are more visible than Libyan state forces in the capital.
The cabinet and Libya's official armed forces are so weak that swathes of the oil-producing desert country remain outside central government control.
A spokesman for parliament admitted it was unclear whether the vote would be enough to dislodge the gunmen from their positions outside the government buildings.
"We hope the siege of the ministries will stop now, but it is not in our hands," General National Congress (GNC) spokesman Omar Hmaiden told a news conference after the vote.
More than a dozen vehicles mounted with anti-aircraft weapons and machine guns remained parked outside the Justice Ministry and the Foreign Ministry has been similarly encircled for a week.
One of the men stationed by a machine gun in front of the Justice Ministry, said the group came from different areas close to the capital Tripoli and ahead of the vote vowed they would stay until the prime minister had been forced from office.
"We have been asking them to deal with Gaddafi's friends for a year," he said.
Although the law passed with an overwhelming majority of 164 votes in favor and just four against, many congress members were upset.
"It's a very unfair and extreme law, but we need to put national interests first in order to solve the crisis," said Tawfiq Breik, spokesman for the liberal National Forces Alliance (NFA) bloc, Libya's largest parliamentary coalition.
Diplomats in Tripoli complained that holding the vote under duress had undermined its legitimacy, while a human rights group called on parliament to reject the draft.
"The GNC should not allow itself to be railroaded into making very bad laws because groups of armed men are demanding it," said Sarah Leah Whitson, a Human Rights Watch director in the region, in a statement.
"Libya's long-term prospects for peace and security will be seriously diminished if the congress agrees to nod through this law."
Much will depend on how high up in Gaddafi's administration an official has to have been in order to be excluded from politics, one analyst said.
"If the bar is too low, the law could result in most government administrations being gutted, without having sufficient staff or institutional memory to ensure their proper functioning," said Geoff Porter of North Africa Risk Consulting.
"However, if the bar is too high then we are likely to see repeats of the blockades in front of government ministries that we saw this week."
Congress members say the law could be applied to around 40 others in the 200-member parliament, including the president of the assembly Mohammed Magarief who became an exiled leader of Libya's oldest opposition movement in the 1980s after serving as an ambassador under Gaddafi.
The law does not make provisions for those, like him, who spent decades in exile and were instrumental in toppling Gaddafi.
The law prohibits former officials from holding any position in government or even belonging to a political party. It will also ban them from leadership roles in the country's state firms, like the National Oil Corporation, its universities and judicial bodies.
(Reporting by Jessica Donati and Ghaith Shennib; Editing by Jon Hemming)