Police said most of the victims were Shiites. A Shiite television report put the death toll at 72, but religiously affiliated stations often favor high-end estimates of casualties from attacks on their sects.
Meanwhile, it was a deadly day in Iraq for the U.S. military, with three soldiers killed in separate incidents. Officials say small-arms fire in western Baghdad killed one soldier, while another died in an explosion in the southern part of the city. The third soldier was killed in western Iraq, with the military saying only that the death was "due to enemy action."
Monday's attack in Mahmoudiya began about 9 a.m. with a brief mortar barrage, followed by an armed assault by dozens of gunmen. They killed three Iraqi soldiers at a checkpoint, then stormed the market, firing automatic weapons and rocket propelled grenades, police Capt. Rashid al-Samaraie said.
Iraqi troops arrested two suspects in a nearby house and seized weapons, including a sack of grenades, the U.S. military said. AP Television News video showed charred vendor stalls and burned out vehicles lining the market area along a four-lane street running through the town.
In other developments:
In Baghdad, Shiite lawmakers from two parties, including one led by radical cleric Muqtada al-Sadr, stormed out of a parliament session to protest the Mahmoudiya killings.
The attack also sent shock waves through Mahmoudiya, an agricultural center with Shiites living in the town center and Sunnis in the outlying neighborhoods. Frantic relatives milled about the hospital, scuffling with guards and Iraqi soldiers who tried to keep order.
"You are strong men only when you face us, but you let them do what they did to us," one man shouted at a guard.
Some of the victims were transported to hospitals in Baghdad, where a Shiite television station, Al-Forat, put the death toll at 72. Al-Forat aired quotes from Shiites blaming the attack on Sunni religious extremists and expressing outrage over the failure of mainstream Sunni politicians to stop them.
Mahmoudiya has long been a flashpoint of Sunni-Shiite tension and the scene of frequent bombings and shootings. It is located in the "triangle of death," an area of frequent attacks on Iraqi and U.S. troops and Shiites traveling between Baghdad and religious centers to the south.
Police said most of the victims were Shiites, and it appeared the raid was part of the escalating campaign of tit-for-tat sectarian killings that have plunged the country to the brink of civil war.
The main Sunni bloc in parliament said the attack may have been in retaliation for the kidnapping of seven Sunnis, whose bodies were found Sunday in Mahmoudiya. The bloc accused Iraqi security forces, dominated by Shiites, for failing to control the situation.
The Mahmoudiya raid occurred one day after a suicide bomber detonated explosives inside a cafe packed with Shiites in Tuz Khormato, a mostly Turkomen city 130 miles north of Baghdad. Maj. Gen. Anwar Mohammed Amin said 26 people were killed and 22 injured.
Also Sunday, gunmen seized Adel Kazzaz, director of the North Oil Co., shortly after he left the Oil Ministry in eastern Baghdad, ministry spokesman Assem Jihad said. The North Oil Co., operates oil fields around Kirkuk.
The northern fields have been plagued for years by sabotage attacks on pipelines and other infrastructure. Oil exports were restored last month after a long delay but halted again last week and not expected to resume soon.
In the south, a British soldier was killed and another wounded during a raid Sunday against a "terrorist suspect" in Basra, the British military said. Police said British troops had arrested Sajid Badir, leader of the Shiite-based Mahdi Army in the city but it was unclear if the British soldier was killed in that raid.
The officials spoke on condition of anonymity because of fears of retaliation by the militia group, which wields considerable power and has infiltrated the police.
Last May, Prime Minister Nouri al-Maliki declared a state of emergency in Basra, the country's second-largest city and a major oil-producing center, vowing to wield an "iron fist" to end militia rule there.
Al-Maliki, a Shiite, is under strong pressure to disband the militias, including the Mahdi Army, which is run by radical cleric Muqtada al-Sadr. The militias are accused of fanning the flames of sectarian violence.