Militiamen loyal to Shiite cleric Moqtada Sadr surrendered the sacred shrine of Imam Ali on Friday and then surrendered weapons as well, bringing a largely peaceful end to a ferocious three-week battle with U.S. forces that challenged the authority of Iraq's interim government by holding hostage one of the country's most hallowed places.

"Drop your weapons and leave Najaf and Kufa," a voice on loudspeakers began instructing fighters mid-morning, reading a statement from Sadr. "You have done a great job."

A spokesman for Sadr said fighters were withdrawing, but that their militia was not being disbanded.

Obeying terms of a peace agreement that were essentially dictated by Grand Ayatollah Ali Sistani, the senior Shiite cleric in Iraq who swept into the holy city Thursday afternoon to negotiate the truce, the tattered fighters of Sadr's Mahdi Army militia stacked weapons at Sadr's office.

The young men later disappeared into the crowd of jubilant worshippers that Sistani had sent marching past the ruins that defined the front line with U.S. forces and through gates of the shrine's blue-and-green tiled walls. The arrangement allowed Sistani to regain control of the shrine and the militiamen to depart discretely.

Within an hour, U.S. tanks and other armored vehicles roared to life and began to fall back from positions surrounding three sides of the mosque. Iraqi commandos, soldiers and police scrambled to take the Americans' place, asserting control in a city center redolent of death.

Many of the decaying bodies were those of militiamen killed at their firing positions in buildings shattered by overwhelming U.S. firepower. In rubble-strewn streets suddenly safe for civilians, residents led ambulances to recover the casualties where they fell.

Iraqi police followed one overpowering stench to a building they said had served as an illegal religious court for Sadr's organization. People as far away as Baghdad who were accused of drinking beer or other activities deemed un-Islamic were said to have been bundled into car trunks and taken to Najaf for trial. Civil authorities had tried to close the court, which at one point indicted a local civil law judge, according to local attorneys.

Authorities said most of the bodies found when police broke down the door Friday afternoon were police officers and members of the Iraqi National Guard. Sadr followers were said to have targeted, tortured and mutilated the victims over a period of months, deeming them American collaborators.

"We had information about this court," said Lt. Col. Mohammed Dayakh Mohammed, chief of the Najaf police's homicide division. He said between 20 and 25 bodies were recovered, including those of a child of 12 or 13 and an elderly woman.

[According to the Associated Press, an official at the court said the bodies were those of people killed during the fighting with U.S. forces.]

Adel Hadi Hasan, the uncle of Najaf's police chief, was one of seven prisoners found alive. Weak, dirty and unshaven, he said he was held for 20 days after being abducted by three Mahdi Army fighters who shot at his car.

"They wanted to do a deal with the chief of police," Hasan said. "There was one who was really mean. He tortured me."

The whereabouts of Sadr, a junior cleric and scion of an esteemed religious family, remained unknown Friday. But under the terms of the peace agreement, Iraq's government agreed not to arrest him, either for directing the militia or on charges he was behind the April 2003 murder of a fellow cleric.

Several U.S. field commanders said they expected to fight the Mahdi Army again, perhaps in the northeast Baghdad slum called Sadr City, the home of many of the militiamen and the scene of sometimes-intense fighting this month. Iraqi police and U.S. forces set up roadblocks around Najaf and Kufa, which adjoins the holy city to the east, to check departing vehicles for arms.

Under the peace deal, only forces of the interim government can operate and possess weapons; the Mahdi Army and foreign forces are to leave. But for now, the U.S. military will remain to monitor compliance, according to a spokesman for the 11th Marine Expeditionary Unit.

In Kufa, which has been a Sadr stronghold, there was no sign of the militia on the streets during the day Friday. But in the early evening, an Iraqi police patrol was attacked with a rocket-propelled grenade, killing one officer and wounding five, according to Najaf police.

"Their low-level fighters are easily replaced," a Marine officer said. "Hopefully what we did was damage their stockpiles and damage their leadership. What's most important is, hopefully, this damages Sadr politically."

Sistani issued a statement thanking the thousands who answered his summons to march to the shrine. Grand Ayatollah Kadim Haeri, who formerly supported Sadr, issued a religious edict commending Sistani's intervention. "Chaos is forbidden," Haeri declared.

Anger at the Americans and the interim government was easy to find among civilians who stepped gingerly into the streets Friday to inspect horrendous damage in sections of the city of 600,000. Millions of Muslims worldwide know Najaf from pilgrimages to the Imam Ali shrine and the seminaries that long made the city the world's leading center of study for Shiites.

"We blame Ayad Allawi and the government for this damage," said Jasim Aziz, 31, referring to the Iraqi interim prime minister. Aziz had traveled from Balad, 140 miles to the north, to visit the shrine. "They could have waited until Sistani arrived and solved the problems without destroying the city and killing all the civilians and the Iraqis."

"They asked the Americans to destroy the city," said Hussein Mailu, 55, referring to government leaders. "If they did not ask them, they wouldn't do it. Is this the democracy of Allawi? Saddam was so bad but he didn't do this thing," he said, referring to former president Saddam Hussein. "It was beautiful, but not any more."

The day appeared to boost the spirits of the interim government's forces.

Iraqi police drove around the city celebrating by firing into the air from blue-and-white squad cars.

Four battalions of Iraqi security forces received tea and water from residents as they arrived in the city center with the handful of American advisers who had trained them.

"People received us clapping, and by the will of God we will replace the U.S. Army," said Sgt. Sabah Muhsin Sarhan of the 2nd Battalion of the Iraqi Intervention Force, the name for the anti-insurgency force in elements of the new army are called. "Our job is to protect our country, and we don't want the foreigners. We don't want the Jews to control us."

Spirits among Sadr's followers appeared relatively high as well. In Baghdad, an aide claimed the Mahdi Army withdrawal as a victory because U.S. forces never entered the shrine -- something U.S. commanders had publicly vowed not to do under any circumstances. Iraqi commandos had been training for any final assault.

"Young men should learn from Moqtada Sadr and follow him as a leader," Raed Kadhimi, a sheik, said in a sermon at the capital's largest Shiite mosque. "I want to tell those who don't know what happened in Najaf that we destroyed many tanks and killed many U.S. soldiers. We are very happy because we won."

That sentiment was shared by a mother who found her son outside the Najaf shrine.

"You are a hero," declared the woman, who gave her name as Um Hussein. "You were fighting for the Imam Ali and for the sayyid and for Najaf." Sayyid, a reference to Sadr, is an honorific reserved for descendants of the prophet Muhammad.

Special correspondent Luma Mousawi contributed from Baghdad

Iraqis pray at the door of the Imam Ali shrine, which served as a base for the Mahdi Army militia during three weeks of fighting with U.S. and Iraqi forces.