* Ramadi tribes turn on al Qaeda fighters
* Anbar violence is test of strength for Maliki
* Syria war feeding instability in Iraq
By Suadad al-Salhy
BAGHDAD, Jan 3 (Reuters) - Dressed in black and waving al Qaeda flags, Islamist insurgents battled tribesmen for control of the Iraqi city of Ramadi on Friday, while in Fallujah they grabbed loudspeakers after weekly prayers to call for support.
The militants, who have been tightening their grip on the Anbar region near war-torn Syria for months, stormed police stations in both cities on Wednesday. The next day, the Sunni tribesmen made a deal with Iraq's Shi'ite-led government to fight them. Dozens of militants were reported killed on Friday.
"There is no way to let al Qaeda keep any foothold in Anbar," said one tribal leader, who asked not to be named. "The battle is fierce and not easy because they are hiding inside residential areas."
The turmoil, and recent deadly attacks in Lebanon, illustrate how the war in Syria, where mostly Sunni rebels are battling President Bashar al Assad, who is backed by Shi'ite power Iran, threatens to tear apart neighbouring countries.
Al Qaeda's Islamic State of Iraq and the Levant (ISIL) is trying to create a state ruled according to strict medieval Sunni Islamic practice across the Iraqi-Syrian border and has joined forces with powerful groups fighting against Assad.
At least 40 of the militants, who fought with machine guns and pick-up trucks mounted with anti-aircraft guns, were killed in Ramadi, medical and tribal sources told Reuters. There was no casualty figure for tribesmen or security forces.
The army, which had withdrawn from Anbar on Monday, has been deployed on the outskirts of Ramadi and Falluja to back the tribesmen against al Qaeda, in what is set to be a critical test of strength for the government.
TIPPING THE BALANCE?
The deal with the tribesmen against al Qaeda echoed a decision by local tribes in 2006 to join forces with U.S. troops and rise up against al Qaeda forces who seized control of most of Iraq's Sunni areas after the 2003 U.S. invasion.
American troops and local tribes finally beat al Qaeda back in heavy fighting after a "surge" of U.S. forces in 2006-07.
Tension has been high in Anbar, which occupies a third of Iraq's territory, since police broke up a Sunni protest camp on Monday. At least 13 people were killed in clashes.
Many Iraqis feared the country was heading for an explosion of Shi'ite-on-Sunni bloodshed that would fracture it along sectarian lines.
On Thursday tribesmen, angry at what they perceive as Sunni marginalisation in politics, clashed with Iraqi troops trying to regain control of Falluja and Ramadi.
But the late Thursday agreement between the tribes and the government appeared to go some way towards tipping the balance against Islamist militants seeking to establish local control.
"Those people are criminals who want to take over the city and kill the community," said Sheikh Rafe'a Abdulkareem Albu Fahad, who is leading the tribal fight against al-Qaeda in Ramadi.
He said around 60 militants were killed in the fighting, declining to give a casualty figure for the other side. Reuters could not independently verify that death toll.
Fighting was getting increasingly difficult as militants had positioned snipers on top of the buildings, Fahad said.
Further complicating the situation, not all the tribesmen were prepared to join the fighting against al Qaeda in Anbar, where tribal ties are strong.
"Some tribes are against this fighting. They cannot do anything but they are just not cooperating," said one tribal leader on condition of anonymity.
There were no clashes between tribesmen and militants in Falluja, eyewitnesses said, but masked insurgents have control over large parts of the city and have set up several checkpoints in the city.
Islamist militants grabbed loudspeakers after Friday's prayers to call on worshippers to back them, the witnesses said. (Writing by Rania El Gamal; editing by William Maclean and Philippa Fletcher)