GHARYAN, Libya — Rival Libyan fighters who clashed in towns south of Tripoli have settled their deadly dispute through a prisoner swap and agreed to a ceasefire, local officials said on Monday.

"Last night (Sunday) we carried out a prisoner swap... since then, the fighting has stopped," Colonel Ahmed Omar Ibrahim al-Fakhi of the Gharyan military council told AFP.

"We had captured around 24 fighters from Assaba. They had captured four of our men. We exchanged the prisoners in Gharyan," he added.

Doctor Ibrahim al-Karim, deputy head of central Gharyan hospital, said four people were killed and more than 50 wounded in the clashes which erupted on Friday.

Witnesses said the fighting broke out after a man from Gharyan was stabbed and stripped naked in a vegetable market between the adjacent towns of Assaba and Gharyan, some 80 kilometres (50 miles) south of Tripoli.

Fighters of The Martyrs Brigade of Gharyan said they came under fire from Assaba while setting up a checkpoint near the market area after the incident. Intense fighting involving rockets and machinegun fire ensued.

"The people who attacked us from Assaba are loyalists of (ousted leader) Moamer Kadhafi," said Mohammed al-Matati, a Gharyan fighter receiving treatment for burn wounds at the hospital.

The fierce clashes saw Prime Minister Abdel Rahim al-Kib, Defence Minister Osama al-Juili and Libyan mufti Sadeq al-Gharyani visit the flashpoint area in a bid to stop the firefight. Their presence helped broker a ceasefire.

Ibrahim Omar Saadi, head of Gharyan civil council, told reporters that the towns had sent civil and military representatives to Tripoli where they negotiated a 48-hour ceasefire that came into effect at 1500 GMT on Sunday.

He said Gharyan had passed on three demands to the Assaba delegates.

"We want them to hand over their weapons to the defence ministry... to hand over the murderers of five of our rebels who were killed on September 10... and to hand over to the government (former) Kadhafi soldiers" in Assaba.

Saadi accused Kadhafi loyalists of sparking the unrest. "The fighting was between Gharyan revolutionaries and Kadhafi loyalists" in Assaba, he said.

Denying that the fighting was between two rival militias made up of former rebels who had helped topple Kadhafi, Saadi said the town of Assaba had a long history of loyalty to the former leader.

"We know who those people are. We have documents to prove that those fighting revolutionaries of Gharyan are soldiers from Kadhafi's army," added Ismail al-Ayeb, the spokesman of the Gharyan civil council.

He said that during the anti-Kadhafi conflict Assaba men had received heavy weapons from the former regime.

"After the end of the conflict they handed back some small arms, but kept back the heavy weapons which they are using against our revolutionaries," Ayeb said.

Gharyan residents and former rebels said the real problem between the two towns was the "murder" of five former rebels by Assaba men on September 10.

During the peak of the conflict in September, nine anti-Kadhafi rebels from Gharyan were killed in clashes with Assaba locals and five were captured.

"Our five wounded revolutionaries were murdered in Assaba hospital. We want those who killed them to surrender," said Matati, who had defected from Kadhafi's army to join the rebellion against him.

"We hope that the ceasefire will help in solving the issue. We expect that our demands will be met," he added.