Syrian armed groups have mostly withdrawn from a Lebanese border town they had seized, taking with them captive Lebanese soldiers, as a truce to end deadly fighting there appeared to be holding.

Dozens of people have been killed in five days of fighting in Arsal between the army and fighters which began after soldiers detained a Syrian man accused of  belonging to al-Qaeda's Syrian affiliate the al-Nusra Front.

Al Jazeera's Zeina Khodr, reporting from Arsal, said: "The military standoff is almost over. The Lebanese army commander said the situation is good and the army is in control.

"Armed fighters linked to the Islamic State group and al-Nusra Front have withdrawn from Arsal and are now on the outskirts."

Civilians, the majority of them Syrian refugees who were trapped inside Arsal, are now being evacuated by the Lebanese Red Cross, Khodr said.

Mediating clerics

Muslim clerics who had been mediating an end to the fighting said they would negotiate for the release of the remaining captives held by the fighters whose incursion into Lebanon marked the most serious spillover of Syria's war.

Security officials say 19 soldiers are still missing, presumed taken by fighters when they attacked Arsal on Saturday in what the army described as a long-planned attack. More than a dozen policemen were also taken captive.

The mediators from the Muslim Clerics Association on Wednesday secured the release of three of the soldiers.

"We can confirm that the town is almost free of [fighters]," said one of the mediating clerics during a televised news conference speaking on the outskirts of the town. "Within hours everything will be over."

At least 17 Lebanese soldiers have been killed.

A Syrian doctor in Arsal put the total civilian death toll at 42, while security sources have reported dozens of fatalities among the fighters.

Arsal is a Sunni Muslim town at the border where tens of thousands of refugees have taken shelter from the war in neighbouring Syria.

Their refugee camps have been badly damaged in the fighting, Syrian activists and witnesses have reported.

Source: Al Jazeera and agencies