Tripoli (AFP) - At least 28 people were killed and nearly 130 wounded in fierce clashes in the Libyan capital Friday between forces loyal to the UN-backed unity government and rival militiamen, the health ministry said.

Tripoli has been gripped by a power struggle between dozens of militias since a NATO-backed uprising toppled longtime dictator Moamer Kadhafi in 2011.

Health ministry spokesman Anwar Frajallah gave a provisional toll of 28 dead and 128 wounded but could not say if they included any civilians.

Hashem Bishr, a security official for the Government of National Accord (GNA), separately gave a toll of 23 loyalist forces killed and more than 29 wounded.

Medical sources were not immediately available to confirm the figures.

In the south of Tripoli, an armed group loyal to the GNA seized a prison holding senior officials of the Kadhafi regime, a judicial source said.

Guards at Al-Hadhba jail were forced to withdraw after the attack, said the source who requested anonymity, adding that two guards were killed.

By late Friday the GNA interior and justice ministries said in a joint statement that all the prisoners had been handed over to them and were "in good health".

More than 30 senior figures of the toppled regime were held in the prison, including Kadhafi's last prime minister Baghdadi al-Mahmudi and his former intelligence chief, Abdullah Senussi. Both were condemned to death in 2015.

- 'Civilians must be protected' -

Friday's fighting broke out in residential neighbourhoods. AFP journalists heard explosions and artillery fire rock the Abu Slim, Al-Hadhba and Salaheddin districts in the south of the city.

UN Libya envoy Martin Kobler appealed for a halt to the fighting.

"Voices of reason should prevail for the benefit of the country," he said. "Political aims must not be pursued through violence. Civilians must be protected."

Witnesses said tanks had been deployed in the fighting.

British ambassador Peter Millett tweeted that he could hear explosions and artillery in south Tripoli.

Story continues

He condemned "action by these militias who threaten security" ahead of the Muslim holy month of Ramadan, which begins on Saturday in Libya.

Groups hostile to the GNA said they had attacked loyalist forces.

By late afternoon the fighting had subsided, but intermittent gunfire could still be heard in several areas of the capital.

- 'Nothing stops them' -

The fighting started around a complex of luxury villas that until March had served as the headquarters of militias loyal to former prime minister Khalifa Ghweil.

Ghweil was ousted from power when the GNA took office in March 2016, and has refused to recognise the new administration.

Loyalist forces seized the villas in four days of intense fighting in March that saw them expand their control over the capital.

Tripoli had been relatively calm since, but dozens of armed groups still operate there -- including several that support Ghweil.

The GNA has won the support of various militias since it took office in March last year, but several parts of Tripoli remain beyond its control.

Relying on militia support and pitted against a rival administration in the east, the GNA has struggled to assert its authority.

In a statement on Friday, the GNA blamed Ghweil and Salah Badi, both leaders of the Fajr Libya coalition of militias which took power in Tripoli in 2014, and vowed to "retaliate mercilessly".

They "have exceeded all limits... Nothing stops them, not faith, not law, not custom and not morals," it said.

"This is their gift to the people for the month of Ramadan", the statement said.