BAGHDAD — At least 27 people were killed today when looters who were stealing from an oil pipeline inadvertently set off a huge explosion outside Diwaniya, Iraqi officials said.

One official said that the looters had taken advantage of the turmoil that engulfed the southern city on Monday when Iraqi Army soldiers clashed with members of a militia loyal to Moktada al-Sadr, the radical Shiite cleric. At least 28 people died during the fighting.

"The looters seized the security vacuum yesterday as the police protecting the pipeline withdrew from their posts," said Dr. Hussain al-Janabi, director of the Diwaniya hospital. He said he was told that the explosion took place when one of the looters "lit up his lighter to see if his jerry can was full or not."

Dr. Hamid al-Shwaili, the general director of the Diwaniya health office, said that 27 dead and 37 wounded had been taken to area hospitals, and that bodies continued to be removed from the site of the explosion.

The fighting on Monday, which one Iraqi general said included militiamen executing disarmed Iraqi soldiers in a public square, amounted to the most brazen clashes in recent memory between Iraqi government forces and Mr. Sadr's militia.

After weeks of rising tensions and skirmishes between elements of the militia and American-led forces, the violence in Diwaniya could increase pressure on Prime Minister Nuri Kamal al-Maliki, a conservative Shiite, to find a way - political or military or both - to rein in Mr. Sadr's powerful militia.

The battle erupted after a particularly violent weekend in Iraq for American soldiers and Iraqi civilians, in what had been a relatively quiet month.

The American military today announced the deaths on Monday of two soldiers, one from wounds suffered when his vehicle rolled over into a canal on Aug. 21, and one who was wounded in a clash with insurgents in al-Anbar province on Monday. Nine American service members died in attacks on Sunday.

In Baghdad today, police officials found the bodies of 11 men who had been handcuffed, tortured, shot and left behind a school. On Monday, a car bomb killed at least 13 people in the capital and wounded dozens at a checkpoint just outside the Interior Ministry headquarters.

Over all, more than 100 Iraqis were killed Sunday and Monday.

With sectarian violence soaring, American generals and the American ambassador, Zalmay Khalilzad, say that militias are now the single greatest threat to the stability of Iraq and that the Iraqi government must make them disband.

But Mr. Maliki has yet to introduce any new policy, and has refrained from strong condemnations of Mr. Sadr's militia, the Mahdi Army. Mr. Maliki relies on Mr. Sadr, who is enormously popular among poor Shiites, for political support against rival Shiite politicians. Mr. Sadr controls several ministries and at least 30 seats in Parliament, and he maintains close ties to Mr. Maliki's political group, the Islamic Dawa Party.

Earlier this month, after the Americans called in air support during a raid with Iraqi forces in a Sadr stronghold in Baghdad, Mr. Maliki denounced the move by the Americans and said he had never given permission for it.

The fighting on Monday in Diwaniya, in the south, underscored the recalcitrant, rebellious nature of the Mahdi Army and raised the specter of the two uprisings that Mr. Sadr led against the Americans and the Iraqi government in 2004.

After several hours of gunfire and mortars, "the clashes reached a point where members of the militias executed soldiers after their ammunition ran out in a public square, in front of residents," said Maj. Gen. Othman al-Ghanimi, commander of the Eighth Division of the Iraqi Army in Diwaniya. "This is true terrorism and a crime."

The Mahdi Army denied the reports of executions.

The fighting ended only after Shiite politicians visited Mr. Sadr's office in Najaf to negotiate a cease-fire.An American military official said more than 70 people were wounded Monday during the battle, including 40 civilians. Reports from Iraqi authorities and Sadr officials offered similar tallies.

General Ghanimi and other Iraqi Army and police officials said several militias were involved, not just the Mahdi Army. But they said the seed of the violence on Monday was planted a week ago when a roadside bomb they believe was placed by the Mahdi Army killed at least two Iraqi soldiers. Two days later, the Iraqi Army arrested a member of the Mahdi Army.

Nasir al-Saadi, a spokesman for the Sadr bloc in Parliament, said the unidentified Sadr militant arrested by the army was tortured and may have been killed. According to Mr. Saadi's account, the army started attacking a Mahdi-dominated neighborhood late Sunday night. He said the soldiers killed civilians and damaged houses while Sadr militants "did not participate" at first, refusing to return fire.

General Ghanimi, a Sunni, denied torturing the Mahdi detainee, noting that Sadr representatives visited him on Saturday and found him healthy. He said they asked for the accused bomber's release and when the army refused, fighting broke out as the militias sought to free him from custody.

An error has occurred. Please try again later.

You are already subscribed to this email.

Gunfire riddled the streets from around 2 a.m. to the early afternoon. Polish troops responsible for the area helped Iraqi soldiers encircle the most violent areas, as American helicopters hovered overhead without dropping bombs, according to an American official who declined to be identified because the information is supposed to be released by the Iraqi Army.

Khalil Jalil Hamza, the governor of Diwaniya, later shuttled to Mr. Sadr's headquarters in Najaf to discuss a cease-fire, Sadr officials said. By 5:30 p.m., the battle had ended. Mr. Hamza is a senior official in the Supreme Council for the Islamic Revolution in Iraq, a rival Shiite party.

The Mahdi Army and the military wing of the Supreme Council, the Badr Brigade, have fought pitched battles several times in Baghdad and the south in recent years.

According to someone who identified himself as a Mahdi fighter involved in the clash, a prisoner exchange was still being negotiated Monday night. In a telephone interview, the fighter, who called himself Abu Abbas, said the Mahdi Army had taken several soldiers captive and would trade them for the detainee that Iraqi commanders accused of being involved in the roadside bombing. He was reached through a known member of the Mahdi Army, who vouched for his membership.

He said that a local judge had approved the militant's release before the fighting started but that the Iraqi Army refused to accept the ruling. When asked why the Mahdi militants killed more than a dozen other Iraqis, he said, "We know they are our brothers, but the Americans are pushing them against us."

Agence France-Presse today quoted a member of the Diwaniya city council, Sheik Ghanim Abid, as saying that the Army agreed not to enter residential neighborhoods for three days. The Mahdi Army agreed to withdraw its fighters, and the police promised that the member of the Mahdi Army whose arrest appears to have precipitated the fighting will be tried quickly, according to Mr. Abid.

"We are now watching the militia withdrawing," an Iraqi army captain told the news service.

Iraqi, American and British officials continue to assert that a civil war here can be averted.

Maj. Gen. William B. Caldwell IV, the lead spokesman for the American military, said Monday that attacks and murders in Baghdad declined in August thanks to the deployment of about 12,000 additional American and Iraqi troops. He said several neighborhoods searched over the past few weeks under a new security plan were reviving, with stores re-opening, and children riding bicycles in the streets.

Yet Mr. Sadr and the Mahdi Army remain an obstacle. Prime Minister Maliki, a Shiite who depends on support from Mr. Sadr's allies in Parliament, has not confronted Mr. Sadr publicly. Sadr City, a Mahdi bastion, has not been searched or raided in a thorough manner, even though it is one of the capital's most violent areas.

The Americans have maintained some distance: even as the fighting raged in Diwaniya on Monday, General Caldwell told reporters he had not been briefed on the battle and could not comment.

Several clashes have erupted between the Mahdi Army and American-led forces this summer.

In July, American and Iraqi troops stormed a building in Sadr City and engaged in firefights that killed or wounded 30 to 40 gunmen before capturing a militia commander. Days later, British troops raided Al Garma, a town near the southern port at Basra, and detained a Sadr official, Sajad Badr al-Sukany. At least one British soldier was killed in the operation.

Ambassador Khalilzad said in an interview this month that Iran had been inciting splinter groups of the Mahdi Army to step up attacks against American-led forces in retaliation for the Israeli attacks in Lebanon.

General Caldwell said days later that some militia elements had been training in Iran and had received weapons from groups or individuals in Iran, though it was unclear whether the Iranian government was involved.

The battle in Diwaniya took place on a particularly bloody day for Iraqi forces. The car bombing in Baghdad killed at least a dozen Interior Ministry police officers, and wounded at least 35 other officers, a ministry official said. Another policeman was killed when a roadside bomb exploded in southern Baghdad.

In Mosul, the authorities said an Iraqi policeman was gunned down in front of his house, while the police killed one insurgent in a separate clash.

Of the nine American soldiers killed Sunday, four died after their armored Stryker unit was ambushed by a bomb and gunfire in Ghazaliya, a western Baghdad neighborhood that was part of the new security plan and had been described as a model of improved security. Three were killed in two separate roadside bomb attacks, and one from small-arms fire in or near Baghdad. One was killed in Anbar Province.

Defense Minister Abdul Qader Mohammed Jasim, at a joint news conference with the British defense secretary, said the Iraqi government would do everything it could to make the country safe.

"There are criminals and killers - we know the scum who wear the mask of the jihad and religion," Mr. Jasim said. "They used to kill people as criminals and now they kill them under the cover of jihad."