Inmates have staged a major jailbreak at a prison in the east Libyan city of Benghazi as the facility was also attacked from the outside.
Security official Mohammed Hejazi said the prisoners staged a riot inside Koyfiya prison as an attack took place outside the facility.
Gunmen fired into the air outside the prison as inmates began setting fires inside, suggesting the escape was pre-planned.
Special forces later arrested 18 of those who escaped, while other returned on their own, according to security officials.
It was unclear if the jailbreak was part of protests taking place at the offices of Islamist-allied parties in Libya's main cities.
Those who escaped either face or had been convicted of serious charges.
Protesters have massed across the country angry over the killing of an activist critical of the country's Muslim Brotherhood group.
Hundreds gathered in the capital Tripoli to denounce the shooting of Abdul Salam al Musmari, setting fire to tyres and demanding the dissolution of Islamist parties.
Al Musmari, who publicly criticised the Brotherhood, was killed by unknown attackers in a drive-by shooting in Benghazi.
Benghazi's security situation is among the most precarious in post-revolution Libya.
Last year, the US ambassador and three other Americans were killed in an attack there.
Libyan prime minister Ali Zeidan said he would reshuffle the cabinet and reorganise the government to cope with the "urgent" situation.
He added: "What is happening is an attempt to obstruct the state's progression."
The country's government is struggling to assert its authority over armed groups that helped topple Colonel Gaddafi in 2011 during the Arab Spring uprisings.
It comes after Iraq's prime minister Nouri al Maliki ordered the detention of several senior security officials in connection with a major jailbreak that saw hundreds of inmates escape from the notorious Abu Ghraib prison outside Baghdad.
A statement from his office said those detained included the chief of staff of the federal police's fourth division.
Al Qaeda's Iraq branch claimed responsibility for the attack and a simultaneous raid on Taji prison. Members of the terror organisation were among the prisoners thought to have escaped.
People queue to vote in a school being used as a polling station
Soldiers sit outside a polling station
A ballot paper showing all the presidential candidates
A woman gets her finger marked with ink to cast her vote
A man places his ballot in the box at a polling station in Timbuktu
The polls come after months of political turmoil
The injured were taken to hospitals in the area
Authorities are investigating the cause of the accident
Jewish settler homes in the West Bank
Palestinians celebrate UN statehood decision
Investigating judge Luis Alaez is due to question the train driver
The train wreckage remains at the crash scene near Santiago de Compostela
Up to three million people were on Copacabana Beach for the Mass
Pope Francis waves to the crowds from his car