* Rebel infighting has killed thousands of people this year
* ISIL had been weakened by clashes in northwest areas
* Army ambush reportedly kills 20 rebels west of Homs (Adds updated death toll, analyst comment)
By Alexander Dziadosz
BEIRUT, March 14 (Reuters) - An al Qaeda splinter group in Syria finished pulling out of two provinces in the country's northwest on Friday and headed to its eastern strongholds after months of clashes with rival rebels, activists said.
The Islamic State in Iraq and the Levant (ISIL), a former al Qaeda affiliate, and competing insurgents have been fighting since the start of the year, killing some 4,000 people and undermining the revolt against President Bashar al-Assad.
The fighting has weakened ISIL in the northwestern areas, as have recent defections from their ranks, compelling it to leave its bases there and focus on consolidating control in eastern areas where they have a stronger presence, activists said.
On Friday, ISIL finished withdrawing from Idlib and Latakia provinces and moved its forces toward the eastern Raqqa province and the eastern outskirts of the northern city of Aleppo, the Britain-based Syrian Observatory for Human Rights said.
The Observatory, a monitoring group with a network of sources in Syria, said the withdrawal started about a week ago and was overseen by the Nusra Front, al Qaeda's branch in Syria, making the two provinces "completely free" of ISIL forces.
Aymenn Jawad Al-Tamimi, a fellow at U.S.-based think tank the Middle East Forum, said that following the withdrawal ISIL was likely to focus on strengthening its position in Raqqa, Hasaka and eastern Aleppo provinces.
"Basically, what's happening is that each side is consolidating its own positions," he said. "So really it's heading to a stalemate and each side builds its influence in its respective areas."
ISIL, which draws strength from a core of experienced foreign fighters, was initially welcomed in many rebel-controlled areas because of its fighting prowess and reputation for being relatively free of corruption.
The group later alienated many residents with a drive to implement a strict interpretation of Islamic law, but it has also maintained sympathy in some areas because of its reputation for keeping looting and thievery in check.
"There's been an uneasy calm on all sides" since the withdrawal of ISIL forces, one activist from Idlib province said. "Civilians aren't celebrating because ISIL had eliminated thieves and bandits."
Another activist based near the Turkish border said a number of ISIL fighters, most of them foreign, were reported to have departed over the border in recent days.
Separately on Friday, the Observatory raised its estimated death toll from the rebel infighting to about 4,000 people since the start of the year, including hundreds of civilians.
A video posted online on Friday showed two fighters touring what they said were abandoned buildings that had been used by ISIL as a court and a prison in a town in the Jebel al-Akrad region. One fighter said the withdrawal had happened peacefully after negotiations between ISIL and other rebels.
ISIL began as a re-branding of al Qaeda's branch in neigbouring Iraq, but the parent organisation announced it was cutting ties with the group last month over its refusal to limit itself to fighting in Iraq.
The Nusra Front, al Qaeda's Syria branch, has occasionally clashed with ISIL. But it has also tried to broker truces between ISIL and rival factions and fought alongside the group against government forces in other areas.
The infighting has nevertheless further complicated a war that has killed over 140,000 people and forced millions to flee their homes. The war enters its fourth year this month.
In a separate incident, the Syrian army killed 20 militants in an ambush in Tel Kalakh, a village 40 km (25 miles) west of Homs, a military source told Reuters. Lebanon's Al Manar television channel also reported the incident.
The source said the attack happened near a customs checkpoint close to the border with Lebanon, about 4 km (2.5 miles) from the village.
Pro-government Twitter accounts said the militants had been trying to enter Lebanon's Wadi Khaled after fleeing the Sunni town of al-Hosn. Reuters could not independently verify those reports.
The source also said Syria's army had reached the eastern entrances of Yabroud, a rebel-held town near the border with Lebanon where the military has been making recent advances. (Additional reporting by Stephen Kalin and Mariam Karouny; Editing by Tom Heneghan, Larry King)
Our Standards: The Thomson Reuters Trust Principles.