Benghazi jailbreak.
Prisoners including supporters of former dictator Col Gaddafi escaped al Kwafiya prison in a mass jailbreak early on Saturday

Libyan security forces are scrambling to recapture up to 1,200 inmates who escaped from a prison near the eastern city of Benghazi following riots on Saturday.

The mass jailbreak at al Kwafiya prison came as demonstrators staged angry rallies across the country in protest at the assassination of a prominent political activist on Friday.

Abdul Salam al Musmari led a group which was among the first to stage the protests that led to the 2011 revolution and subsequent removal of dictator Muammar Gaddafi.

Hundreds gathered in the capital, Tripoli, on Saturday for the funeral of al Musmari, a vocal critic of the Muslim Brotherhood.

Protesters ransacked Muslim Brotherhood offices, demanding the dissolution of Islamist parties in the country.

The prison break began at dawn, amid confused reports of rioting inside the jail, and the arrival of armed gunmen at the gates.

Inmates then set fire to the prison complex as the gunmen fired into the compound from outside, according to reports.

The escapees included Gaddafi supporters who had been charged with attacking security bases after the conflict, according to reports.

Others either faced or had been convicted of the most serious criminal charges, a security official told the Associated Press. Other escapees were believed to be foreign nationals.

Special forces later recaptured 18 of the escapees, while others returned on their own, said Mohammed Hejazi, a government security official in Benghazi.

Three inmates were shot by security guards as they tried to escape, and were in hospital, according to reports.

Libyan Prime Minister Ali Zeidan said residents in the southern area of the city had stormed the prison as they objected to its presence in their area.

He ordered the closure of the country's Egyptian border, and pledged to scour the breadth of the country to recapture the fugitives.

"The prison was [attacked] by the citizens who live nearby because they don't want a prison in their region" he said.

"Special forces were present and could have got the situation under control by using their arms but they had orders not [to use] their weapons on citizens... so the citizens opened the doors to the prisoners."

There had been unrest inside the prison before the breakout, according to sources.

"There was a riot inside al-Kwafiya prison, as well as an attack from outside," a security official told Agence-France Presse. "Special forces called in as reinforcements were given orders not to fire at the prisoners."

Two military officials were also killed in Benghazi on Friday.

Supporters of al Musmari accused the Muslim Brotherhood of involvement in his killing, while others criticised the government's slow response to the violence.

Benghazi was known as a hotbed of dissent as the Arab Spring revolutions began. Last year the US ambassador Chris Stevens and three other Americans were killed there.