* Ansar al Sharia listed as terrorist group by U.S.
* Was accused of role in 2012 killing of U.S. ambassador
* Libya in chaos, worst crisis since 2011 civil war
* Unrest depresses N.African state's oil production (Updates with Ansar al-Sharia warning, U.S. comment, background)
By Ayman Al-Warfalli
BENGHAZI, Libya, May 27 (Reuters) - The leader of Islamist militant group Ansar al-Sharia in Libya's Benghazi city warned the United States on Tuesday against interference or it would face worse than the conflicts in Somalia, Iraq, or Afghanistan.
Libya's young democracy is in turmoil three years after the NATO-backed war that ousted Muammar Gaddafi, with rival Islamist, anti-Islamist, regional and political factions locked in a complex struggle for influence in the OPEC member state.
Four decades of Gaddafi's one-man rule left few institutions or national army to resist competing militias and brigades of former rebels who have become de facto power-brokers.
Ansar al-Sharia, listed as a foreign terrorist organisation by Washington, was accused of orchestrating the 2012 attack on the U.S. consulate in Benghazi in which U.S. Ambassador Chris Stevens and three other Americans died.
Mohamed Zahawi, head of the Benghazi brigade of Ansar al-Sharia, accused the U.S. government of backing renegade former general Khalifa Haftar, who has begun a self-declared campaign to purge Libya of Islamist militants.
"We remind America, if they intervene, of their defeats in Afghanistan, Iraq and Somalia, because they would face in Libya something much worse," he said in a statement. "It was America who urged Haftar to turn the country towards war and bloodshed."
The United States has an embassy in Tripoli, but closed its consulate in Benghazi after the 2012 attack.
A former general under Gaddafi, Haftar earlier this month launched attacks with his irregular forces on Islamist militant bases in Benghazi because he said the government had failed.
Ansar al-Sharia also runs a network of social services in the city and has operated its own checkpoints.
Many Libyans are fed up with violence and Islamist militants accused of assassinations and bombings especially in the eastern city, and Haftar gained some support from regular army units.
But forces claiming loyalty to him also stormed the Tripoli parliament a week ago, and he demanded the legislature hand over powers in a further challenge to the vast North African country's already stumbling transition to democracy.
Asked about Zahawi's assertion that Washington was backing Haftar, a U.S. official in Washington replied: "That's ridiculous, but coming from a terrorist, not unexpected."
The U.S. official, who spoke on condition of anonymity, said the United States opposed political violence by all sides in Libya. "Our position is clear - political violence will not solve Libya's political problems. We call upon all parties in Libya to work constructively and productively toward finding solutions to the current crisis."
CHALLENGE TO STATE
Earlier on Tuesday, unidentified gunmen fired grenades at the Tripoli home of new Prime Minister Ahmed Maiteeq, and his guards killed at least one assailant, just days after parliament approved his appointment in a contested vote.
Full details of the morning attack were not clear, but Maiteeq, who is Libya's third premier in two months, was unharmed. "There were two cars and they fired RPGs (rocket-propelled grenades) at his home," a source from the prime minister's office said.
A businessman from Misrata, Maiteeq won backing from an Islamist party and independents in a chaotic vote challenged as illegitimate by rival lawmakers and anti-Islamist factions including Haftar.
Some lawmakers and officials have demanded that Maiteeq's predecessor stay on because the vote in parliament was not valid according to a justice ministry legal department.
Early elections have been called for June as a way to defuse tensions, but many Libyans believe they may not be enough to bridge deepening divisions over the country's transition.
Worried that unrest may spill over into anarchy across the wider North African region, the United States and European Union have been helping train Libya's nascent army. But constant turmoil has undermined programmes to forge an effective force.
At stake also are Libya's large oil resources. They have been squeezed by months of blockades by an array of former rebel groups and local protesters whose demands range from more autonomy to better payments.
Ibrahim Jathran, a former rebel commander, defected from a state-run oil guards brigade with his men to take over four major oil ports last summer to demand more autonomy for his region.
Jathran had agreed to lift his blockade steadily under a deal with the government. But late on Monday he said he did not recognise Maiteeq's government, suggesting the oil deal may be in jeopardy.
Port shutdowns by Jathran's armed fighters and other protests have cut Libya's output to 160,000 barrels per day from the 1.4 million it was churning out beforehand. (Additional reporting by Ahmed Elumami and Feras Bosalum in Tripoli, Arshad Mohammed in Washington; writing by Patrick Markey; Editing by Mark Heinrich)