TRIPOLI, Libya — Libya's newly formed national assembly elected former opposition leader Mohammed el-Megarif as the country's interim president on Friday, the latest move to establish a democratically based leadership after decades of rule by deposed dictator Moammar Gadhafi.

El-Megarif won 113 votes to defeat another opposition leader and human rights lawyer, Ali Zidan, who won 85 votes from the 200-member General National Congress, an assembly created in the first nationwide election since Gadhafi's ouster and killing last year. Both men had been diplomats who defected and fought Gadhafi's regime while living in exile since the 1980s.

"This is a historic moment and no one is a loser," said Hussein al-Ansari, an independent lawmaker speaking after the victor was announced.

El-Megarif, who authored a series of books on Gadhafi's repressive policies, lived as a wanted fugitive for years.