The first phase of a troubled population transfer has concluded, with thousands of displaced Syrians evacuated out of besieged areas and an agreement reached to release hundreds of government detainees, according to government news media and rebels.

One of the largest evacuations in Syria's civil war had been tied to the fate of 26 hostages, including members of Qatar's ruling family, who had been held by a Shia militia in Iraq and were released on Friday.

Qatar, the patron of some Syrian armed opposition groups, was a main negotiator of the deal. Iran, which backs Iraqi and Lebanese fighters in Syria, served as the other negotiator.

With the transfer completed on Friday, the first phase of the population swap deal in Syria comes to an end.

A total of 8,000 residents from the pro-government villages of Foua and Kefraya - besieged for two years amid Syria's bloody civil war by anti-government rebels - and nearly 3,000 evacuees from the rebel-held Zabadani, Madaya and surrounding areas have left their homes.

Under the deal, an estimated 30,000 people will be transferred from their hometowns over 60 days, most of them from the pro-government villages in northern Idlib.

It is one Syria's largest population transfers, which the opposition has described as "demographic engineering", and the first to involve a reciprocal population swap.

The Syrian military media arm said 46 buses carrying residents of Foua and Kefraya arrived in Jibreen, an Aleppo suburb, on Friday. Some 15 buses were carrying residents and rebels from the Zabadani area, which was besieged by the government, departed for Idlib.

Rebel spokesman Mohammed Abo Zayed, from the Ahrar al-Sham rebel group negotiating the deal, said the phase ended with the agreement to release 500 detainees from government prisons who are expected to arrive at a rebel-held area near Aleppo city later Friday.

Another 250 detainees will be released in the next 10 days, he said.

OPINION: Absurdity is questioning a dictator's motives

Syrian media declared that armed groups no longer have any presence in the Zabadani and Madaya areas, which government troops entered after the evacuation. The Syrian military said it had destroyed a tunnel linking the two areas.

Madaya and Zabadani, once summer resorts to Damascus, have been shattered under a crippling government siege. The two towns rebelled against Damascus' authority in 2011 when demonstrations swept through the country demanding the end of President Bashar al-Assad's rule.

The blockades forced residents to resort to hunting rodents and eating leaves off trees. Photos of children gaunt with hunger shocked the world, but the siege remained.

In northern Syria, civilians in Foua and Kefraya, besieged by the rebels, lived under a steady hail of rockets and mortars. They were supplied with food and medicine through military airdrops.

The population transfer faced a number of snags, including a deadly explosion a week ago.

The massive bombing targeted a packed convoy carrying evacuees from Foua and Kefraya, killing at least 126 people, including more than 60 children.

Rights groups have decried the agreement as a forced displacement that is altering the country's demographics along political and sectarian lines.

In the last year alone, thousands of rebels, along with their families and supporters, were forced to surrender in capitulation deals under intense government bombings and tight sieges across a number of towns and areas around the capital Damascus, as well as in Aleppo and Homs. Most of those have been transferred to rebel-held Idlib.

Syrian state TV al-Ikhbariya broadcast the arrival of several buses carrying hundreds of residents to Jibreen, where the government set up temporary shelters.

Relatives rushed to the buses to receive their loved ones, who had been stranded at an exchange point since Wednesday. Others frantically searched for missing relatives.

Lebanese Al-Manar TV, affiliated with Syrian government ally Hezbollah, said at least 12 bodies of those killed in the Saturday explosion were among those arriving in Aleppo.

"Whoever knows anything about my kids, please let me know," a mother wept on al-Ikhbariya as she pleaded for information for her three children missing since the explosion last week.

No one has claimed responsibility for the bloody blast.

In pictures from rebel-held areas, one armed man could be seen hugging another after the buses arrived in rural Idlib.

UN Syria humanitarian adviser Jan Egeland said there had been more evacuation deals this year than before, but they appeared driven more by military priorities than humanitarian concerns.

"They seem to follow a military logic, they do not seem to put the civilians at the heart of the agreement," he told reporters in Geneva on Thursday.

The United Nations was not involved in the evacuation of the four towns, Egeland said, adding it was misleading to consider them voluntary evacuations when the towns had been besieged for years.

"Besiegement should end by being lifted," he said, "not by places being emptied from people."