Some 400 detainees escaped after a riot on Sunday at a prison in the southern suburbs of the Libyan capital Tripoli, theatre of a week of deadly battles, police said.

"The detainees were able to force open the doors and leave" as fighting between rival militias raged near the prison of Ain Zara, police said in a statement, without specifying what crimes the escapees had committed.

Guards were unable to prevent the prisoners escaping as they feared for their own lives, the statement said.

Most detainees at the prison have been convicted of common crimes or were supporters of former dictator Muammar Gaddafi, found guilty of killings during the uprising that toppled his regime in 2011

According to a health ministry toll, at least 39 people have been killed and some 100 injured since clashes, including rocket fire, broke out among rival militias on Monday in suburbs south of Tripoli.