Tunis (AFP) - Dozens of Tunisians held in Libya by a militia forming part of an alliance ruling Tripoli have been freed, the foreign ministry announced Saturday.

"All the Tunisians being held in Libya have been freed. The final group was released today," the ministry said in a statement, without giving numbers.

In Tripoli, Mohamed Abdelsalam al-Kuwiri, who heads a unit in the Tripoli-based government that combats illegal migration, told AFP that a final group of 90 Tunisians was released on Saturday, two days after 71 others were freed.

They had been held for verification of their identity papers, he said.

Tunis announced earlier in May that scores of its nationals were being held in western Libya by a militia belonging to the Libya Dawn alliance.

Kuwiri said last week that his officers had helped secure the release of a first group comprising dozens.

A foreign ministry official, speaking anonymously, told AFP on Saturday that a total of 245 Tunisians had been detained, all of whom had now been freed.

According to Tunisia's foreign ministry, its nationals were detained "to check their documents".

But the Tunisian consul in Tripoli has said they were apparently taken as bargaining chips for a Libyan militia commander arrested in Tunis.

Libya has been wracked by conflict since the 2011 overthrow of veteran dictator Moamer Kadhafi in a NATO-backed uprising, with rival governments and powerful militias battling for power.