* National assembly agrees to follow sharia law
* Decision seen as a way to undermine hardliners (Adds comments from lawmakers, context)
By Feras Bosalum
TRIPOLI, Dec 4 (Reuters) - Libya's national assembly voted on Wednesday to make Islamic law, or sharia, the source of all legislation, in an apparent bid by moderate Islamists to outflank ultra-conservative militants who have been gaining influence.
Two years after the NATO-backed uprising that ousted Muammar Gaddafi, Libya is still in messy transition, with no new constitution, a temporary government and nascent security forces struggling to contain militias and former rebels.
The immediate impact of the statement was not clear in the already overwhelmingly Muslim country, though it could affect criminal and financial legislation.
"The legislative system does not contain many laws that contradict Islamic law so it is easy to say sharia would be the sole source of legislation," said Ibrahim al-Gharyani of the National Forces Alliance party.
But lawmakers suggested at least part of the reason for the statement from the General National Congress (GNC) was political.
As in Tunisia and Egypt, where autocratic leaders were also ousted in the Arab Spring revolts, Libya has seen fierce debate over the role of Islam in its new democracy with the rise of ultraconservative Islamists long suppressed by Gaddafi.
The hardline group Ansar al-Sharia, blamed for the 2012 attack on the U.S. consulate in Benghazi, has been attempting to extend its influence, and has accused some assembly members of being un-Islamic. Its militants have clashed with the armed forces in the east of the country.
"This statement will close the gap on anyone who says the GNC is not working parallel with sharia law," said Mohammed al-Zaroug, from the Muslim Brotherhood's Justice and Construction Party (JCP) which promotes Islamic law.
The Congress statement said the assembly had agreed Islamic law was the source of legislation and that a special committee would review existing laws to ensure they comply with sharia.
Unlike codified Western law, sharia is more loosely defined moral and legal guidelines based on the Koran, the sayings of Prophet Mohammad and Muslim traditions.
One reform if Libya applies sharia may be a shift to more Islamic finance regulation, based on religious principles which avoid interest and pure speculation.
The Congress's decision came shortly before a vote to form a 60-member committee that will draft a new constitution. (Additional reporting by Ghaith Shennib; writing by Patrick Markey; Editing by Andrew Heavens)