Magarief, a moderate Islamist, will head the congress, which is also set to name a prime minister, enact laws and guide the north African Libya towards parliamentary elections after a new constitution is drafted in 2013.
Magarief, leader of the National Front party, is the acting head of state, although the actual extent of his powers is still to be determined. An economist and former ambassador to India who lived in exile since the 1980s, Magarief was a key man in the National Front for the Salvation of Libya, the country's oldest opposition movement, which made several attempts to topple the late Muammar Gaddafi.
The 72-year-old National Front Party, an offshoot of the old opposition movement, had won three seats in the July 7 poll, Libya's first free poll in a long, long time.
Magarief won 113 votes against the Independent Ali Zidan, who got 85 votes. the polling continued into a second round after no one got a majority in the first round.
Zidan, while congratulating Magarief, said this was the good side of democracy. The national assembly also voted Giuma Attaiga, a lawyer from Misrata, as Magarief's deputy.
Othman Sassi, a former official of the National Transitional Council, said Magarief has good experience in leading congress and the Libyan democracy. Magarief is from Benghazi, the country's second biggest city and the cradle of the 2011 revolt.
The national assembly started functioning on Wednesday when it took over from the National Transitional Council, the political arm of the opposition that dethroned Gaddafi and now stands dissolved. It was the first peaceful power transfer in modern Libyan history although it has been overshadowed by the recent violence.
In the 200-strong assembly, 80 seats are held by the parties. a liberal coalition led by Mahmoud Jibril won 39 of those seats while the Justice and Construction Party, the political wing of the Muslim Brotherhood, won 17. The remaining seats are in the hands of Independent candidates.
(With agency inputs)