BEIRUT (Reuters) - The evacuation of thousands of people from two loyalist Syrian villages that were besieged by rebels in the northwest is complete, state media said on Thursday, with the government expected to release hundreds of detainees in return.

Syrian state-run al-Ikhbariya TV said all buses had left al-Foua and Kefraya by Thursday morning, making the two Shi’ite villages “empty of civilians”.

The buses are traveling through rebel-held territory and have not yet reached a government check point around 30 km (18 miles)away from the villages, al-Ikhbariya said.

More than 100 buses arrived on Wednesday to transport residents and fighters overnight from the villages to nearby government-held territory in Aleppo province.

The evacuation began with ambulances ferrying out the sick to a government checkpoint, before around 121 buses departed the villages.

Al-Ikhbariya TV said 10 ambulances carrying a number of people in critical condition left the villages.

The villages have been under siege for years by Sunni Islamist rebels in Idlib province, the last major insurgent-held part of Syria. President Bashar al-Assad, who is advancing against rebels in the southwest, has vowed to recover the entire country.

Slideshow ( 21 images )

Some 7,000 people are due to leave both villages.

Population transfers have been a common feature of the seven-year Syrian war, mostly at the expense of Assad’s opponents. The conflict has killed an estimated half a million people and driven some 11 million from their homes.

Rebels and civilians have been bussed out of their hometowns to insurgent territory in the north, as government forces advanced with critical help from Russia and Iran.

The opposition has decried it as a systematic policy of forcible displacement against those opposed to Assad, who comes from the Alawite sect, an offshoot of Shi’ite Islam.

The conflict took on a sectarian dimension as it swelled out of protests against Assad’s rule in 2011. Shi’ite Islamist militias backed by Iran have deployed from across the region to help Damascus against rebels, many of whom identified themselves as Sunni Islamists.

Opposition sources said officials from Hayat Tahrir al-Sham, a coalition spearheaded by Syria’s former al-Qaeda offshoot, and Iran’s Revolutionary Guards had negotiated the latest swap.

Slideshow ( 21 images )

A commander in the regional alliance that backs Assad and an Islamist rebel source familiar with the secret talks said separately that Turkey was also involved in the process, which builds on a deal from last year that had not been fully implemented.

State TV said 121 buses had entered al-Foua and Kefraya in Idlib province so far on Wednesday, along with Syrian Arab Red Crescent (SARC) ambulances for sick residents.

The evacuees will include Alawite hostages that rebel factions took when they overran Idlib more than three years ago, it said.

In April last year, thousands of people were shuttled out of the two villages to government territory in a similar mediated agreement.

In exchange, hundreds of residents left two towns at the border with Lebanon, Madaya and Zabadani, which were in the hands of Sunni rebels at the time and under siege from pro-government forces. They were moved to Idlib.

But other parts of the deal - evacuating the people remaining in al-Foua and Kefraya and releasing 1,500 detainees from state prisons - did not go through at the time.