Rioting inmates at Kabul's main prison agreed to halt violence late Monday and prison authorities restored supplies of water, electricity and food cut off a day earlier in an attempt to put down the revolt, officials said.

The sounds of gunfire and inmates shouting "God is Great" could be heard as authorities negotiated with prisoners controlling most of the facility. A government negotiator said four inmates had died in the two-day standoff blamed on Al Qaeda and Taliban militants.

Security forces backed by tanks and heavy guns surrounded the notorious prison.

Sibghatullah Mujaddedi, the chief government negotiator, said the rioting inmates had agreed to temporarily halt violence.

"I promised them I would do my best to solve their problems and they trust me," Mujaddedi said. "They said they would not launch any more attacks right now."

Abdul Salaam Bakshi, chief of prisons in Afghanistan, said the situation was calmer on Monday night.

"The food, water and electricity have been restored. For the time being, I am optimistic. Everything is quiet. Let's see what happens tomorrow," Bakshi said.

Earlier in the day, authorities warned they were prepared to use force to end it.

"We can take all these prisoners in one hour," deputy justice minister Mohammed Qasim Hashimzai told The Associated Press as he traveled to the prison Monday. "But to prevent bloodshed we are trying to negotiate."

Government negotiator Mohammed Ibrahim Sahdat told journalists after talking to the prisoners that four rioters had been killed and 38 wounded during the siege.

The prison holds about 2,000 inmates. The area now under the inmates' control includes a wing that houses 70 women prisoners and about 70 children who live with them.

Officials said the violence began when inmates refused to put on new uniforms, which were ordered after seven Taliban prisoners escaped last month by disguising themselves as visitors.

The riot started late Saturday in Block Two of the prison, which houses about 1,300 of the 2,000 inmates, including 350 Al Qaeda and Taliban loyalists.

Hashimzai confirmed that rioting spread Sunday to Block One, which houses hundreds more inmates. No prisoners had escaped, he said.

A man claiming to be a spokesman for the Block One inmates called The Associated Press and demanded retrials for all the prisoners, saying many were innocent while others were serving unfairly harsh sentences.

The man, who identified himself only as Maqsodi, said the riot would continue until the government met prisoners' demands.

"Two-thirds of the prisoners here are innocent. The courts were unfair," he said. It was not possible to immediately confirm the man's identity.

Sahdat, the government negotiator who is also a member of the Afghan Independent Human Rights Commission, confirmed that some prisoners were demanding their cases be retried.

Security forces had yet to gain access to parts of the jail under prisoner control that include the wing with the women and children.

A senior government official, speaking on condition of anonymity because of the sensitivity of the matter, said the prisoners dug a tunnel to that wing to reach it. Soldiers at the prison, however, reported the prisoners had made a hole in a wall.

Hashimzai said attempts to negotiate the women's release from the rioters' control floundered Sunday because of disunity among the inmates and confusion over their demands.

Mir Hayatullah Hashimi, another deputy minister of justice, said prisoners had demanded negotiations with top government officials, including the chief of Afghanistan's reconciliation commission, a vice president and the chief of the Supreme Court.

Policharki was built in the 1970s and is notorious for its harsh and crowded conditions. But it is under renovation ahead of the expected arrival of some 110 Afghan terror suspects later this year from the U.S. military prison at Guantanamo Bay, Cuba, Afghan officials say.

Riots and breakouts have cast doubts over its readiness.

In December 2004, four inmates and four guards died during a 10-hour standoff that started when some Al Qaeda militants used razors to wrest guns from guards and then tried to break out.

Afghan troops stormed the prison and fired guns and rocket-propelled grenades to retake control.