Updated

Libya's parliament chief, who served under Moammar Gadhafi before becoming an opposition leader in exile, resigned on Tuesday, just weeks after lawmakers passed a bill banning former regime officials from senior government posts.

The law, which may effectively bar the parliament speaker, Mohammed al-Megarif, and several other experienced Libyan leaders from politics, was adopted on May 5 amid much turmoil and pressure by militias.

Al-Megarif, his eyes welling up with tears as he announced his resignation before the General National Congress in the capital, Tripoli, said he was stepping down out of respect for democracy.

"All must comply with the law out of respect for the legitimacy and institutionalization of democracy," said al-Megarif, adding that he is the first official to resign in accordance with the law.

Under Gadhafi, al-Megarif was Libya's ambassador to India in 1980 before he joined the opposition against the former dictator in exile.

After the former dictator's ouster in the eight-month civil war and his slaying at the hands of rebels in 2011, al-Megarif returned to the country and was elected to parliament in Libya's first free elections last year.

Some of the militias were former rebel groups who fought Gadhafi. Their power has mushroomed since, and the country's nascent government has struggled to reign in the fighters who do not answer to any central authority. The government also continues to rely on some to provide security.

Al-Megarif suggested lawmakers passed the so-called Political Isolation Law under threat of force and decried what he described as the empowerment of some legislators backed by gunmen.

The new law is to come into effect June 5, but a committee will look into the case of each official before he is ousted.

"The use of force, threatening to use force, or brandishing force ... do not conform with the building of and transition to democracy that we all seek," al-Megarif said.

Much of Libya's turmoil ahead of the law being passed took place in Tripoli, where militias besieged government buildings for days to pressure adoption of the new law as their guns were drawn on the streets.

"There are tens of thousands of weapons in the hands of those pretending to be revolutionaries," al-Megarif added. He warned of the need to eradicate Gadhafi-era schemes, including "revenge, antagonism ... and hatred" that still plague Libya.

He is the head of the National Front Party, an offshoot of the exile opposition group he once helped lead, the National Front for the Salvation of Libya.

He will be replaced by deputy head of parliament Juma Attiga until a new speaker is elected by lawmakers.

While in exile, al-Megarif wrote a series of books on Gadhafi's repressive policies. The National Front he was a part of was involved in several assassination attempts on Gadhafi, including a daring 1984 raid on Bab al-Aziziyah, the late dictator's fortified compound in Tripoli.

Gadhafi cracked down on the group, executing and arresting many of its members and forcing others to flee abroad.