El-Megarif was a leader of Libya's oldest opposition movement, the National Front for the Salvation of Libya, which made several attempts to end dictator Moammar Gadhafi's 42-year rule, sometimes by plotting his assassination, the Associated Press reported.
El-Megarif won out in the vote after midnight over another opposition figure, Ali Zidan. Both were former diplomats living in exile since the 1980s.
El-Megarif is from Libya's second city, Benghazi, where the revolution began. He is considered a moderate Islamist and close to the Muslim Brotherhood, the BBC reported.
Until a new constitution is in place sometime next year, el-Megarif will hold the office replacing Mustafa Abdul-Jalil, head of the outgoing National Transitional Council, which was disbanded Wednesday when Abdul-Jalil handed power to the new assembly.