The United Nations refugee agency has evacuated 325 African refugees from the Qasr Ben Gashir detention centre in southern Tripoli because of deteriorating security and escalating violence.
The refugees - mainly Eritrean, Sudanese and Nigerian - were taken to a detention centre on Wednesday in Zawiya, a town west of the Libyan capital, where they were at "reduced risk," the UNHCR said in a statement.
The latest evacuation, which followed a protest and violence at the facility on Tuesday that left 12 injured inmates needing hospital care, brought to 825 the number of refugees and migrants transferred farther from clashes in the past two weeks.
The agency called for the release of the remaining 3,000 in custody.
"The dangers for refugees and migrants in Tripoli have never been greater than they are at present," said Matthew Brook, UNHCR deputy chief of mission in Libya.
"It is vital that refugees in danger can be released and evacuated to safety."
More than 3,600 jailed refugees have been trapped in the capital since forces from the east of the country started an advance to capture it, the UN says.
'We don't want to leave'
Earlier on Wednesday, Libyan officials opened the doors of a detention centre for illegal refugees in Tripoli, but frightened Somalis and other sub-Saharan Africans told the Reuters news agency they had decided to stay there for fear of getting caught up in fighting engulfing the capital.
"We don't want to leave... We have no place to go," said a 20-year-old refugee who gave his name as Daoud, sitting on a mattress in a packed warehouse where 550 migrants have been held.
His pregnant wife sat with other women in a different room also lacking air conditioning, trying to endure the sweltering heat.
In the quieter eastern Tajoura suburb, the manager opened the gate of his detention centre housing refugees from sub-Saharan countries such as Eritrea, Somalia, South Sudan and some Arab countries.
Everyone stayed, surviving on one meal of pasta a day. On a good day, they get two.
Laundry hanging from the ceiling
Large parts of Libya have been lawless since the overthrow of Muammar Gaddafi in 2011, and the country has become the main transit point for hundreds of thousands of refugees from sub-Saharan Africa and the Middle East attempting the dangerous voyage across the Mediterranean Sea to Europe.
Officials have been accused in the past of mistreating detainees who are held by the thousands as part of European-backed efforts to curb smuggling.
At the Tajoura detention centre, authorities have not supplied any food or water since before fighting started last week, said Nour Eldine Qarilti, the director.
"We have not received any assistance from all international organisations," he told Reuters.
"Some local NGOs still support us with simple needs but it's not enough."
Hundreds of refugees lay on mattresses, their few belongings packed in plastic bags or wrapped in towels.
Laundry was hanging from the ceiling. Others were using a kitchen to cook lunch for others for a small fee.
'Terrible litany of violations'
According to the UN, Libya is now hosting more than 700,000 people who have fled their homelands, often trekking through the desert in pursuit of their dream of crossing to a better life in Europe.
They then try to find smugglers to put them on boats. But with Italy and France helping to beef up the Libyan Coast Guard, most now get caught before reaching Europe.
According to one UN report last December, migrants and refugees in Libya suffer a "terrible litany of violations" by a combination of state officials, armed groups and traffickers.
"These include unlawful killings, torture, arbitrary detention, gang rape, slavery, forced labour and extortion," it said.