Another 80 people have been injured in the attack according to a health official, which is being blamed on forces loyal to rebel leader Khalifa Haftar, who launched an offensive to take Tripoli from the internationally recognised government three months ago.
Malek Mersek, spokesman for a state emergency medical services, said 40 people had been killed and 80 wounded in the strike on the detention centre in the Tajoura suburb located next to a military camp.
The Tripoli-based government said in a statement that dozens of people had been killed and wounded in an air strike blamed on the “war criminal Khalifa Haftar”.
Libya is the main jumping off point for thousands of Africans trying to reach Europe. Many are held in government-run detention centres in western Libya in what human rights groups and the United Nations say are often inhuman conditions.
Tajoura, east of Tripoli’s centre, is home to several military camps of forces allied to Libya’s government, which have been targeted by air strikes for weeks.
Tripoli is besieged by Haftar’s Libyan National Army (LNA). It denied hitting the detention camp, claiming it had been shelled by militias loyal to the Libyan government.
Rival factions have been battling for control of Libya and its vast oil and gas reserves since the overthrow of Muammar Gaddafi in 2011.
The country has also become a proxy battleground for regional powers trying to exert their influence.
The LNA has for years been armed by Egypt and the United Arab Emirates, while Turkey has shipped weapons to the Tripoli government.