Jihadists who occupied eastern Lebanon's Arsal near the Syrian border have agreed to leave in 24 hours and to release military and police hostages, Sunni clerics said on Wednesday.
A ceasefire has been "extended to 7 pm on Thursday (1600 GMT) following an agreement between Lebanon's prime minister, the army command and the other concerned parties," chief negotiator Sheikh Hossam al-Ghali said as he left the town.
"Fighters in Arsal have started to head across the Lebanese border" into Syria, Ghali said.
The clerics went to Arsal to negotiate an end to clashes between the army and jihadists that began in the area on Saturday, killing at least 17 soldiers.
An initial truce was expected to run until Wednesday evening, allowing talks to continue and the evacuation of the wounded and trapped civilians.
Lebanon's army says at least 22 of its soldiers have gone missing in the fighting, and are assumed to be held hostage by the militants, along with an estimated 20 policemen.
Another negotiator and fellow cleric, Samih Ezzedine, said: "We don't know how many there are and we have no way of verifying but the remaining armed men have undertaken to leave Arsal completely within 24 hours.
"They asked not to be shot at as they withdraw, and if that happens the whole agreement will be in jeopardy," he said.
"All the prisoners are alive and despite difficult negotiations we have clear and positive promises they will be released. I hope that will happen on Thursday," Ezzedine said.
An Arsal resident told AFP during the day that many of the jihadists appeared to have withdrawn from its streets, though he said he could still see around 20 militants manning a checkpoint near his home.
The UN agency for refugees UNHCR said earlier in the week it had received reports from local field hospitals of 38 people killed and 268 wounded, though there was no official confirmation.
The fighting has prompted Lebanon's army chief to call for more international aid, and on Tuesday night, Lebanon's former prime minister Saad Hariri announced Saudi Arabia had pledged $1 billion.
On Wednesday, Hariri said the money would be made available to the country's security forces immediately.
Hariri, who is Lebanon's top Sunni politician but has resided overseas since the 2005 assassination of his father Rafiq Hariri, said he would be in contact with Lebanon's prime minister, cabinet and military and security apparatus.
Together, he said, they would "examine the programmes, plans and projects that will cater to the urgent needs of the army and contribute directly to the provision of the supplies needed to defeat terrorism."
The new aid pledge came after Saudi Arabia and France said they would both work to speed up implementation of a separate $3 billion arms deal for Lebanon.
That deal, announced last December, involves Saudi financing for the purchase of French equipment, but a list of what will be obtained has yet to be finalised.
The clashes in Arsal are the most serious in the border region since the Syrian conflict erupted in March 2011.
On Wednesday afternoon, an AFP correspondent said ambulances were entering Arsal and a military truck had evacuated some civilians.
A convoy of trucks carrying aid for residents of the town tried to enter, but was blocked by residents from a neighbouring village who said the assistance would end up in the hands of jihadists.
The fighting has raised fears about the stability of Lebanon, which is hosting more than one million Syrian refugees and has seen existing political and sectarian tensions heightened by its neighbour's war.
Many of Lebanon's Sunni Muslims, including residents of Arsal, back the uprising against Syria's President Bashar al-Assad.
But much of the country's Shiite community backs Assad, and the powerful Shiite Hezbollah movement has sent fighters to bolster his forces against the rebels.