BEIRUT -- Some Syrian militant fighters have begun withdrawing from the Lebanese town they captured five days earlier as a new 24-hour ceasefire was announced Wednesday, according to the Lebanese army and the Muslims clerics that mediated the deal.

It is not clear how many militants are actually leaving the border town of Arsal and previous ceasefires have collapsed, but three more captured Lebanese soldiers were released as part of the agreement, according to the mediators in a televised press conference.

"Most of the gunmen have begun moving toward Syria," said Sheik Hussam al-Ghali, a member of the Association of Muslim Scholars group that brokered the ceasefire in what has been the most serious spillover to date from Syria's civil war.

Lebanon's former prime minister, meanwhile, announced that Saudi Arabia is granting another $1 billion in aid to the Lebanese army to support its fight against militants.

Fighting in Arsal first began on Saturday when militants from Syria overran the town, which lies near the border with Syria. They seized Lebanese army positions and captured a number of soldiers and policemen, demanding the release of a prominent Syrian rebel commander, Imad Ahmad Jomaa, who was arrested in Lebanon earlier that day.

At least 17 Lebanese soldiers have been killed and another 22 -- as well as an unknown number of policemen -- have been declared missing. Tens of thousands of Lebanese civilians and Syrian refugees have been trapped by the fighting, and mediators have been trying to work out an arrangement to evacuate wounded civilians from the town.

An initial truce was brokered on Tuesday, but clashes broke out again after the militants opened fire on Lebanese troops the next morning and the delegation of Sunni clerics had to return to the town to mediate a new ceasefire.

A senior Lebanese security official confirmed that the three soldiers were released and said the army has agreed to a new ceasefire to allow for more negotiations and for aid to enter Arsal.

Speaking on condition of anonymity in line with regulations, he confirmed some militants were starting to withdraw but the army was insisting all of them leave.

"Our conditions are clear. We will accept nothing else than a complete withdrawal and the release of all soldiers and policemen," he said.

The capture of Arsal was the first time in Syria's conflict, now in its fourth year, that rebels seeking the overthrow of President Bashar Assad have carried out a large-scale incursion into Lebanon, raising concerns that the tiny country is being further sucked into its larger neighbour's bloodletting.

Former Lebanese Prime Minister Saad Hariri, on a visit to Jiddah, Saudi Arabia, announced that the kingdom was providing the Lebanese army with an additional $1 billion in aid.

The funds are separate from the $3 billion Saudi Arabia pledged in December to help strengthen Lebanon's armed forces with the purchase of weapons from France. That was the biggest grant ever for the Lebanese military, but there have been delays in the delivery of that aid.

The militants in Arsal belong to Syria's al-Qaida affiliate, the Nusra Front, and the more extreme Islamic State group, alongside other smaller Syrian rebel brigades, officials said.

Ahmed al-Qusair, a Syrian activist in contact with the militants, said that the fighters would not totally withdraw unless they had guarantees the Syrian refugees in the town would not be harmed if they pulled out.

Over 170,000 people have been killed in Syria's civil war, nearly a third of them civilians, activists say.

Also Wednesday, a leading rights group called on rebels in Syria to "immediately release" 54 women and children they have held hostage since the rebels seized their villages last year.

The New York-based Human Rights Watch said that the women and children were likely taken because they are Alawite, members of a Shiite offshoot sect to which Assad also belongs, and that the rebels were likely seeking to exchange them for opposition fighters captured by the government.