Updated

For the first time since its meteoric rise in 2012 amid the chaos of war, al-Qaida's branch in Syria is in retreat, battling rival militant groups in the north and fighting for survival in a key foothold near the capital, Damascus.

Over the past three weeks, the extremist group has been driven from nearly all of the northern province of Aleppo, losing dozens of fighters in battles there and in nearby Idlib province.

The fighting poses a major challenge to the militant group, already beset by infighting and a string of assassinations that have taken out some of its top leaders. Unlike previous battles in which al-Qaida-linked fighters were able to quickly crush their opponents, the fighting has been particularly fierce, with the militants losing dozens of villages.

The al-Qaida-linked coalition known as the Levant Liberation Committee is still one of Syria's most powerful armed groups, with fighters numbering in the thousands.

While the U.S.-led coalition and Russian-backed Syrian troops have focused on driving the Islamic State group from the country's east, the al-Qaida-linked group has consolidated its control over Idlib, where it remains the strongest force despite its recent losses there.

After the defeat of IS, al-Qaida is seen as the main jihadi group that rejects any peace talks to try to end Syria's seven-year conflict. Its presence in northern Syria and in the Damascus suburbs of eastern Ghouta has provided a pretext for President Bashar Assad and his Russian backers to wage war against opposition-held territory, since various de-escalation and cease-fire agreements have excluded al-Qaida.

Several hundred al-Qaida fighters holed up in eastern Ghouta have become a burden to the armed opposition battling government forces there, which has pressed the extremists to leave the area for their stronghold in Idlib in order to avoid the current crushing offensive.

The group's presence has also raised concern in nations from Turkey to the United States that fear the global network founded by Osama bin Laden could use its presence in northern Syria to launch terrorist attacks around the world.

The recent fighting appears to have been triggered by last month's assassination of a senior al-Qaida official, Abu Ayman al-Masri, who was riding in a car with his wife when members of a rival militant group, Nour el-Din el-Zinki, fired on their vehicle, killing al-Masri and wounding his wife.

The killing led to battles in Aleppo and Idlib that have raged for the past three weeks.

The shooting was preceded by the merger of Nour el-Din el-Zinki and the ultraconservative Ahrar al-Sham, both former al-Qaida allies now turned enemies.

Amid the recent battles, the new coalition, the Syria Liberation Front, has forced the al-Qaida fighters to retreat west to Idlib.

The insurgents say that the war against al-Qaida will not stop until the jihadi group is crushed in Syria — an ambitious goal. It is also a striking statement, considering the rival groups once turned to al-Qaida's experienced and battle-hardened fighters for support in the battle against Assad's forces.

Yazan Mohammed, a media activist based in Idlib province, said that although al-Qaida has lost some territory in the recent fighting, the group is far from being defeated.

The al-Qaida fighters are "not scouts. They are an organized and powerful group," Mohammed said.

In recent years, tens of thousands of rebels and civilians from around the country have fled to Idlib or been forced there by government troops, raising concerns that the presence of al-Qaida will give the government a pretext to storm the province under the cover of Russian airstrikes as it has elsewhere, including in Aleppo in late 2016 and in the current offensive in the eastern suburbs of Damascus.

Brett McGurk, the top U.S. envoy for the coalition battling IS, said last year that Idlib is the largest al-Qaida haven since bin Laden's days in Afghanistan.

"This war will not stop," said Bassam Haji Mustafa, a senior official with the Nour el-Din el-Zinki group. "This is a real war against al-Qaida, its extremist ideas and terrorism."

After the recent battlefield losses, a senior al-Qaida commander, Abu Yaqzan al-Masri, released an audio asserting the militant group will soon crush the offensive and the focus will again be "to fight infidels," an apparent reference to the West.

The commander's comments coincided with a counteroffensive in which the al-Qaida affiliate regained some villages it had lost earlier, although its presence in Aleppo province has almost ceased to exist.

Local activists said the al-Qaida counteroffensive was backed by members of the Turkistan Islamic Party, a powerful group consisting mostly of jihadis from China's Turkic-speaking Uighur minority.

The Britain-based Syrian Observatory for Human Rights, which tracks Syria's seven-year conflict, says the fighting that broke out on Feb. 20 has killed 223 fighters on both sides, including 132 from al-Qaida's affiliate.

Despite losing dozens of villages in the recent battles, it is unlikely that al-Qaida will be defeated easily in Idlib, where the militants have crushed many of their opponents in recent years.

"They will not be able to defeat the Committee," said Abu Dardaa al-Shami, who sometimes fights with the al-Qaida affiliate but refused to take part in the current battles, saying he only fights against government forces.

"This is mission impossible," he said.