Libya's parliament has passed a law banning officials from the Gaddafi era from holding political office.
The vote in the General National Congress (GNC) came a week after militias backing the law began besieging the ministries of justice and foreign affairs.
They had said they would not leave until the bill was passed.
The law could affect senior members of the government, including Prime Minister Ali Zeidan.
Both Mr Zeidan and GNC speaker Mohamed Megaryef were diplomats before the revolution.
Human rights groups say the measure is too sweeping.
"This law is far too vague - potentially barring anyone who ever worked for the authorities during the four decades of Gaddafi's rule," Human Rights Watch's Sarah Leah Whitson said in a statement on Saturday.
In a vote broadcast live on state TV, 164 MPs supported the measure in the 200-member chamber and just four voted against.
It required a two-thirds plus one majority to pass.
Under the law, anyone who held a key official post between 1969 and 2011 is supposed to be excluded from government.
But it is not clear how long the exclusion will last.
The BBC's Rana Jawad in Tripoli says that while officials and the public at large generally see the law as necessary, many believe other interests are being pursued on all sides under the guise of demands for its adoption.
This includes militias afraid of losing power and political infighting within the congress itself, she adds.
A special commission will now be set up to implement the new law.
In March, protesters barricaded members of the GNC inside the building for hours to call for the new law to be adopted.
Militias blocked the foreign ministry last Sunday, moving in to surround the justice ministry on Tuesday.
But until now officials had been unable to agree the terms of the law.
Since Gaddafi's death, Tripoli and other Libyan cities have been plagued by violence and infighting.
The government has recently tried to dismantle militias that formed during and after the war that toppled the long-serving leader.