CAIRO — Fierce clashes in the Libyan capital of Tripoli are endangering the lives of thousands of mostly African migrants, refugees and asylum seekers held in overcrowded detention centers, the aid agency Doctors Without Borders said Friday.

The fresh violence has renewed criticism over European Union policies to prevent the migrants and others from reaching Europe and instead return them to Libya, where powerful militias and tribes are vying for power.

“The recent fighting demonstrates that Libya is not a safe place for migrants, refugees and asylum seekers,” Ibrahim Younis, the head of Doctors Without Borders in Libya, said in a statement. “. . . These people are already extremely vulnerable, and now they find themselves trapped in yet another conflict without the ability to escape.”

Libya has been at war and in political turmoil since the death of its dictator Moammar Gaddafi in 2011, following the country’s violent Arab Spring revolution. The latest clashes erupted earlier this week between two rival militias both aligned with the Western-backed Government of National Accord (GNA), which controls Tripoli. A separate government is in control of eastern Libya.

As many as 30 people have died in clashes since Monday, as heavy shelling and fighting engulfed residential neighborhoods, according to Libyan Health Ministry officials. The fighting has put more pressure on aid agencies to help growing numbers of Libyans and foreigners without access to food, medicines and health care.

The dispute that triggered the clashes is believed to center on territorial control and efforts by the GNA to get militias to leave Tripoli, according to analysts and local media reports. A cease-fire Thursday quickly dissolved.

The ambassadors of the United States, Britain, France and Italy issued a joint statement Thursday saying they were “deeply concerned about the recent clashes.”

“Pursuing political aims through violence will only further exacerbate the suffering of the population of Libya, and threaten broader stability,” the statement said. “Those who undermine Libya’s peace, security and stability will be held accountable.”

In some areas, the migrants, refugees and asylum seekers spent up to 48 hours in detention centers without access to food, Doctors Without Borders said. Those who were released from detention facilities had no choice but to flee to nearby neighborhoods, where they risked getting killed in the crossfire, the aid group added.

On Thursday, the United Nations refugee agency said in a statement that it had evacuated about 300 refugees and migrants held in the Ain Zara detention center to a safer site because they “were in clear danger of getting caught in the hostilities.” Most of the evacuated were from Eritrea, Ethiopia and Somalia — all nations suffering from conflict or political repression.

Aid agencies say that the vast majority of the migrants, refugees and asylum seekers had tried to reach Europe by boat, but were intercepted at sea and returned to Libya. The E.U. has spent hundreds of millions to equip and train Libya’s coast guard and enhance border security cooperation with several African nations.

But the United Nations and a slew of international aid agencies working in Libya say the policies have worsened the lives of migrants. The detention facilities are more crowded than ever with those who have returned.

In the past few months, Doctors Without Borders said, “the situation has deteriorated” as “limited access to clean water, sanitation, and health care has led to increased physical and mental health consequences.”

“They should not be held captive simply because they were looking for safety or a better life,” Younis said. “They should be immediately released and evacuated to a country where they will be safe.”