Nearly 7,000 prisoners of war are packed into dingy, makeshift jails around Libya, where they have languished for weeks without charges and have faced abuse and even torture, according to human rights groups and interviews with the detainees.

The prisoners will pose an early test of the new government’s ability to rein in powerful militias and break from the cruel legacy of Moammar Gaddafi, who was killed Thursday. Human rights groups have warned that the former dictator’s death — which occurred in captivity after he was punched and kicked by swarming revolutionaries — could constitute a war crime.

Many of Libya’s makeshift prisons are run by local militia groups scarred by the eight-month war and angry at the prisoners, who include Gaddafi fighters and supporters. The new government that is to be named in the next few weeks — after a planned declaration of Libya’s liberation Sunday — will have to deal with both the militias and a crippled national justice system.

So far, the overwhelmed central government has not decided whether Gaddafi-era laws can be used to prosecute his forces.

“What we have been through is something unusual. We don’t have a court that applies for that,” said Ali Sweti, a lawyer who works with the revolutionary government in Misurata, about 130 miles east of Tripoli.

Prisoners captured during the Libyan war stand in a massive dormitory at a makeshift prison run by revolutionary authorities in the city of Misurata. An estimated 7,000 Libyan detainees from the war are in crowded prisons around the country. (Mary Beth Sheridan/WASHINGTON POST)

Sweti, 27, runs a prison that reflects the rough wartime justice at work in Libya. The facility was set up at a high school, and it now holds 1,000 inmates — a tenfold increase since July. They sleep on mattresses laid side by side on the floor, guarded by revolutionaries as young as 19. One recent day, two dozen detainees were lined up waiting to use one small washroom.

The interim national government is planning an amnesty for Gaddafi fighters who have not committed war crimes and who agree to cooperate with the new authorities, according to one government adviser, who was not authorized to speak on the record. But it is unclear whether that will be acceptable in places such as Misurata, where residents endured especially bloody attacks by loyalist forces.

“Some of these [pro-Gaddafi] people raped, some killed. There was vandalism. They tortured us; they killed kids,” said Abdel Gader Abu Shaallah, who oversees two other makeshift prisons in Misurata. “We are emotionally destroyed.”

Militiamen from Misurata captured Gaddafi on Thursday in his home town of Sirte. Cellphone videos show revolutionaries punching and kicking him and pulling his hair, as gunshots ring out in the background. He died in captivity during what the interim government says was an exchange of gunfire with loyalist troops but what human rights groups say could have been an intentional shot to the head. Gaddafi’s body was displayed publicly in Misurata for a second day Saturday.

Mona Rishmawi, a senior U.N. human rights official, said after visiting Libya this month that up to 7,000 prisoners were being held with no judicial process.

“This is, of course, a recipe for abuse,” she told reporters.

Amnesty International and Human Rights Watch have documented numerous cases of ill treatment of detainees. Dark-skinned Libyans and sub-Saharan Africans, the human rights groups say, have been especially vulnerable to beatings and torture by electric shock. Many Libyans suspect those with darker skin of being African mercenaries or of otherwise supporting Gaddafi.

“Right now, you have hundreds of local armed groups that are taking law into their own hands in their own neighborhoods,” said Fred Abrahams, a special adviser at Human Rights Watch.

He said a researcher for his organization was recently in a Misurata prison about midnight and witnessed four wounded detainees from Tawergha — a former Gaddafi stronghold — being forced to move around on their knees in a courtyard, with their hands behind their heads. According to Abrahams, a guard told the researcher: “We do this every day. It is sport before they go to bed. They committed rape.”

Human Rights Watch has found evidence of two prisoners dying from beatings they received in detention, he said.

Several prisoners in Misurata said in interviews that they had been beaten after being detained.

Gouezy Ahmed, 29, a small-boned man with big brown eyes who was lying on a mattress in a military prison, said he was whipped during an initial interrogation.

“Sometimes they hit you here, hit you there, to make you confess,” he said. Ahmed said he had acknowledged being a military officer under Gaddafi.

The revolutionaries overseeing the prisoners were at times openly contemptuous. As Abu Shaallah, the prison official, accompanied a reporter through the military prison, he became exasperated at detainees’ accounts of their innocence.

“Why are you here? Tell the truth,” Abu Shaallah barked at a man who said he was a civilian captured while fleeing Tawergha. The man was a suspected fighter with Gaddafi’s forces, Abu Shaallah said. And didn’t he raise the green flag of the regime over his home?

“We raised the flag because everyone in our city is pro-Gaddafi,” said the man, Abdul Aziz, who declined to give his surname.

A senior security official with Misurata’s revolutionary government acknowledged abuse had occurred in the prisons but said conditions had improved.

“The first couple of months, there was no organization. Some people were tortured or hit,” said the official, Ibrahim Mohammed Shirkasiya. But the revolutionary government now has teams of volunteer lawyers who are conducting investigations of each prisoner, he said. Those deemed innocent are freed.

“Whatever the revolutionaries did in the first two months is nothing compared to what these Gaddafi loyalists did in Misurata,” he said.

Misurata’s chief investigating magistrate said the city’s approximately 2,000 detainees have had no access to the formal justice system.

“We have had no contact with them,” said the magistrate, Abdel Latif Ibrahim al-Hamaly. He said he didn’t know how he would cope with so many prisoners; the city’s three jails and main court building were heavily damaged during the war. Jail guards had not yet returned to work.

Under international law, fighters in a civil war are supposed to be freed once the conflict ends, unless they have committed crimes such as attacking civilians.

“That means Gaddafi’s soldiers can be held while a determination is made as to whether they committed war crimes or other offenses,” Abrahams said. But if they are detained for an extended period, “they need to be brought before a judge.”

Revolutionary leaders in Misurata said they were trying to improve conditions in the prisons but had little money and guidance from the central government. Food, blankets, mattresses and other goods are donated by local residents or international groups, they said.

In one sign of the revolutionaries’ good intentions, the humanitarian organization Doctors Without Borders has been allowed to open clinics in two makeshift prisons in Misurata to treat the war-wounded. Its physicians said food and water in the prisons seemed adequate.

The national government has condemned prisoner abuse. “We joined the revolution to end such mistreatment, not to see it continue in any form,” Prime Minister Mahmoud Jibril told Human Rights Watch in late September.

Abrahams said the Libyan leaders “have been spot on with their public statements. The problem and question is their ability to implement them on the ground.”