Libya's parliament chief has resigned just weeks after lawmakers passed a controversial law banning officials who served under Moammar Gadhafi from senior government posts.

Mohammed al-Megarif, who was Libya's ambassador to India in 1980 before he joined the opposition in exile, announced his resignation on Tuesday.

The new law, which would effectively ban al-Magarif and other experienced leaders from politics, was passed under pressure by militias.

Al-Magarif's eyes welled up as he spoke before the General National Congress in the capital, Tripoli.

He decried what he described as the empowerment of some lawmakers backed by gunmen and warned of the need to eradicate Gadhafi-era schemes, including "revenge, antagonism ... and hatred" that still plague Libya.