Tunisian consular workers freed 'in exchange for Libyan commander'
Ten Tunisian diplomatic staff who were kidnapped in Libya a week ago have been freed and returned home.
Foreign Minister Taieb Bakouch said the consulate had now been closed and urged all Tunisians to leave the country.
He denied reports that the workers were freed in exchange for a Libyan militia commander.
Walid Kalib, who leads a brigade in the "Libya Dawn" alliance which controls Tripoli, was recently arrested in Tunisia on terrorism charges.
Libya Dawn official Jamal Zubia on Wednesday wrote on his Facebook page:
"The page of the Tunisian consulate will be turned and they will return to their families and the revolutionary hero Walid Kalib returns to his family,'' reports AP news agency.
Analysis: Rana Jawad, BBC News, Tunis
Tunisian officials have occasionally advised their nationals to leave Libya in times of crisis there in recent years.
More often than not, these calls are not heeded - this is partly why officials here decided to re-open their consulate in Tripoli in recent months.
Tunisia has very high unemployment and the livelihoods of a large number of its nationals depend on Libya for both skilled and menial jobs, as well as trade.
The recent kidnappings of Tunisia's consular staff served as a reminder of why most embassies pulled out of Tripoli last summer. Militia allegiances shift as frequently as the sand dunes in the Libyan desert.
There is no central security structure that anyone can rely on - not even those who are in power.
In urging Tunisians to leave Libya, Mr Bakouch said "we cannot again be subject to any blackmail," according to the Reuters news agency.
However, he said that the decision to deport Mr Kalib had been taken by the courts, independently of his ministry.
Libya descended into chaos after the uprising that led to the overthrow of Colonel Muammar Gaddafi in 2011.
There has been no central government since then, with different militia groups competing for power.
Most countries closed their embassies during the fighting that ensued, but Tunisia recently sent consular staff back to Tripoli.
The UN is trying to negotiate a political settlement to the crisis in Libya, after insecurity in the capital forced Libya's internationally recognised parliament and government to relocate to the eastern city of Tobruk.
Libya Dawn last year seized control of Tripoli and surrounding areas.