TRIPOLI, Libya — Under pressure from armed militias, Libya’s Parliament passed a sweeping law on Sunday that bans anyone who served as a senior official under Moammar Khadafy during his 42-year-long rule from working in government.
The Political Isolation Law could lead to the dismissal of many current leaders, some of whom had defected to the rebel side during the country’s 2011 civil war or had been elected to office since Khadafy’s ouster and killing.
The move is also likely to further stall the country’s already rocky transition to democracy by ousting elected lawmakers.
It injects a new dose of uncertainty into Libyan politics during a still-fragile transition. Liberals say it will give a boost to Islamists, who performed poorly in recent elections compared with their counterparts in other Arab states, although Islamists said they could also be affected by the ban.
The law was partially driven by the unpopularity of Libya’s current crop of politicians among many of the still-powerful former rebels who toppled Khadafy, and others who say little has improved since. Backers of the law say it is necessary to complete the revolution.
But critics say that the law was passed at gunpoint, as militias have surrounded several government buildings in Tripoli for the past several days barring officials from work. Their vehicles mounted with rocket-propelled grenades kept watch on the street during the vote.
Most of the militias have roots in the rebel groups that fought Khadafy, but they have mushroomed in the two years since his fall. Many of the armed groups have been accused of rights abuses, but the government continues to rely on them to keep order in the absence of a strong police or military. Many militiamen say they mostly want jobs and steady pay.
The General National Congress, Libya’s elected Parliament, voted overwhelmingly in favor of the law. Out of 200 lawmakers, 169 attended the vote.
Deputy head of Parliament Juma Attiga, who oversaw the vote, told the TV station Libya Ahrar that militias had pressured Parliament to vote in favor of the law, but that he had planned to vote yes in any case. He may be affected since he served as head of a governmental rights group under Khadafy.
Prime Minister Ali Zidan could also be among those affected, though his position as a diplomat under Khadafy might not be considered a ‘‘senior’’ post. He defected in 1980 and was elected to Libya’s Parliament before being voted by Jibril’s bloc to head government.
Notably absent from the voting was the head of Congress, Mohammed al-Megarif, who may be ousted under the new law for having served as an ambassador under Khadafy.
Parliamentary spokesman Omar Humeidan said after a live broadcast of the vote that a committee will be formed to see how the new law will be implemented.
The committee will be made up of judges and rights activists already serving on an ‘‘integrity commission’’ that vetted ministers for Khadafy-era ties. That body will be dissolved.
The law highlights the government’s inability to rein in armed groups and exposes the many obstacles the North African nation faces in rebuilding its weak central government.
It comes at a time when Islamists are in a position of strength following the Arab Spring uprisings that saw Libya’s two neighbors — Tunisia and Egypt — oust longtime autocrats from power. As is the case in all three nations, Islamists and liberals are in a power tussle for control over the direction of their countries.
But unlike Egypt and Tunisia, liberals won big in Libya’s first free elections last year. Former rebel leader Mahmoud Jibril’s liberal bloc took nearly half of the seats allocated for party lists. The body has a significant numbers of independents allied with Islamist parties.
Legislators said the law states that parliamentarians who lose their post will be replaced by either the next name on the party list or by the independent candidate who came in second in a district. This could benefit many Islamists, who trailed in the elections and came in second in many districts.
Lawmaker Tawfiq al-Shaybi, who is with Jibril’s bloc, told Libya Ahrar TV that the country’s Muslim Brotherhood party was pushing the law ‘‘in favor of themselves rather that in favor of what is best for the country.’’
Brotherhood lawmaker Majda al-Falah denied that Islamists passed the law to target their opponents.
Several drafts of the bill were debated during the past several months, and it was not immediately clear how the final draft will be applied. Those who it does affect will be banned from government positions for 10 years.
Zeinab al-Targi, another member of Jibril’s coalition in Parliament, said the law essentially criminalizes people by excluding them from political life, even if they sided with the opposition that ousted Khadafy.
Some Libyan activists say the vote is undemocratic since it occurred under the threat of violence from militias.