BAGHDAD -- In the ranks of the Mahdi Army militia, the deadly sectarian fighting that took Iraq to the verge of civil war wasn't so much a crisis as an opportunity.
Thousands of Mahdi fighters loyal to firebrand Shi'ite Muslim cleric Moqtada al-Sadr seized mosques and stormed through Sunni neighborhoods in a show of force that emphasized the wide extent of Sadr's political influence and his ability to provoke mayhem.
The week of lethal disarray that followed the destruction of a Shi'ite shrine in Samarra on Feb. 22 revealed just how much ground the Shi'ite militias have gained during the years they have been officially outlawed.
The role of armed groups in the spate of revenge killings and mosque attacks also highlighted the stark contrast between the thriving militias and the Iraqi Security Forces, still struggling to stand on their own and unable to check paramilitary power through much of Baghdad and the Shi'ite south.
In many areas, like the Sadr City district on the edge of the capital, where 2.3 million mostly poor Shi'ites live, it is militias -- and not occupying US forces or Iraqi police -- who hold sway.
''When you stop terror, and get the occupation out, then you will find us servants to the law," said Abu Barah, 26, who quit his job as a hotel security guard a year ago to work full time as an office manager for the Mahdi Army headquarters in Sadr City.
He laughs dismissively at the prospect of the Iraqi government or the US military enforcing the law that prevents militias from carrying weapons.
After the mosque bombings, fighters in the Mahdi Army, which is thought to have tens of thousands of members, took to the streets to attack Sunni targets, then turned on a dime when Sadr ordered a cease-fire, according to foot soldiers in the movement who defied a blanket ban from their leadership on talking to reporters. In less than a week, Baghdad's morgue was flooded with hundreds of corpses, the result of killings attributed to sectarian retribution attacks that the police, Iraqi Army, and US Army were unable to stop.
Increasingly, the militias are asserting themselves as political, social, as well as military forces, and are trying to make it clear that no government can disband or disregard them.
Since the first US occupation officials took control in 2003, every authority running Iraq has promised to disarm the pervasive militias that control vast portions of the country. The failure to do so is a testament to two trends: the increasing sophistication of militias such as the Mahdi Army and the Badr Organization -- the militia of the Shi'ite political party the Supreme Council for Islamic Revolution in Iraq -- and the continuing weakness of the Iraqi Army and police, who are supervised and trained by US forces.
The militias have presented a challenge to the government's authority that rivals that posed by the Sunni-dominated insurgency, even though the major militias come from political parties with strong representation in the government.
The day of the shrine attack, the country's top leaders, including the Shi'ite Islamist prime minister, the Kurdish president, Sunni political chiefs, and the top Sunni and Shi'ite religious scholars, all called for restraint, urging Shi'ites not to rampage against Sunnis to take revenge.
One crucial voice was silent: Sadr didn't give his Mahdi militia any instructions for a day and a half -- a period when dozens of mosques were attacked and hundreds of Sunnis were driven from their homes, according to displaced people and to Sunni political leaders.
Mahdi fighters, in their signature all-black uniform, seized dozens of Sunni mosques and went door to door ordering Sunnis to flee predominantly Shi'ite areas, according to the Iraqi Islamic Party and the Association of Muslim Scholars, the two preeminent Sunni leadership bodies.
But on the second day after the attack, Sadr ordered his followers to protect Sunnis and asserted that the Mahdi Army had no part in the revenge attacks; he blamed American and Jewish agents disguised as militia members for the violence, saying they were trying to provoke civil strife.
The about-face led to bizarre situations. In one case, the Iraqi Islamic Party said, the same team of Mahdi fighters that set fire to a Baghdad mosque returned later in the day with a firetruck to extinguish the flames.
More important to the Shi'ite members and backers of the militia, the eruption demonstrated that neither the militias nor the political parties they back can be ignored.
''If the occupier only gives us some space, we could get rid of the terrorists. They are holding us back," said Abbas Ridha Kadhum al-Zubaidi, the imam at a Shi'ite shrine in the center of the prosperous Karada district.
He has the backing of the Supreme Council for Islamic Revolution in Iraq, whose militia, the Badr Organization, has been absorbed into many special police units.
Zubaidi openly espouses a belief hinted at by many Iraqi and US officials. ''There is more popular support for the militias than the police," he said. The attempt to create and impose a new national army and police on Iraq that isn't loyal to Shi'ite religious movements, Zubaidi said, is a ''foreign gamble destined to fail."
The Samarra crisis, he said, showed the Americans and the Iraqi government how easily the precarious security balance in Iraq could slip out of control -- and suggested that the two biggest Shi'ite militias could pull the lever on sectarian war at any time.
US Ambassador Zalmay Khalilzad said the Iraqi government cannot foster democracy without first dispatching the militia threat and building an authoritative police force.
''Militias, unauthorized military formations, are threats to a successful democratic order," Khalilzad said. ''The next government has to develop a strategy, and we're willing to work with that government, to deal with this problem."
But Khalilzad learned from his years as ambassador to Afghanistan that it's often impossible to eradicate popular militias.
Even the spokesman for the US military in Iraq, Major General Rick Lynch, acknowledged that ''now is not the time" for the Iraqi government to take on the Shi'ite militias. ''The Mahdi militia is still active and is doing things that it should not be doing," he said.
The Iraqi government, he said, should ''use this opportunity to disband these militias, but nothing is easy."
Without a strong Iraqi Army, it is unlikely that a government could make serious headway disarming militias. The US military has set ambitious goals to train enough Iraqis to lead the counterinsurgency with American support in most of the country by the end of the year.
But Brigadier General Mohammed Askary, an Iraqi defense official who supports the training program, said it would take much longer to build a real national army, not riven by factional or sectarian loyalties, than the optimistic timetable set by the United States.
''It is a good plan, but it is not going as quickly as it should be," said Askary, who described the formation of the Iraqi Army as ''still in crisis."
Since police were called back to work immediately after the fall of Saddam Hussein's government, Iraqi authorities have been plagued by the problem of dual loyalties -- recruits who joined the police but retained primary loyalty to a militia.
But the real problem for the military is that it hasn't developed enough capacity to control the streets in comparatively peaceful parts of Iraq controlled by militias -- such as Sadr City and large portions of the south.
''I joined the army to serve the people, not to be killed by the people," said Ather, a former Iraqi Army lieutenant who wanted only his first name published out of fear that insurgents would target his family if they knew he had been an officer.
Ather quit nearly a year ago after insurgents shot at him when he was leaving work at the joint US-Iraqi base outside Fallujah.
The Mahdi Army, in contrast, commands deep loyalty. Thousands turned out for Sadr's sermon after the Samarra crisis, a nationally televised invective against the US occupation and what he called the Zionist conspiracy.
''We got rid of Saddam's bloody dictatorship and another dictatorship came, the dictatorship of America, Britain, and Israel," he said in a speech peppered with colloquial street Arabic not usually employed by imams. ''So beware of the West's plans."
Nadhum Jawad al-Taiee, a 26-year-old mechanic from the mostly Shi'ite neighborhood of Baladiyat, volunteers for the Mahdi Army in his spare time. He stands guard at the home of frightened neighbors, distributes food and money to the poor, and, most important in his opinion, spreads Sadr's Islamist teachings.
Taiee said his duties, like the overall mission of the Mahdi Army, call for a strategic mix of persuasion and intimidation.
''We advise women to wear the hijab. We advise Muslims not to drink alcohol," he said. ''If someone ignores the advice, they beat him, and after the beating he should be convinced."
Globe correspondent Sa'ad al-Izzi contributed to this report from Baghdad. Thanassis Cambanis can be reached at firstname.lastname@example.org.