At least 52 people were killed as security forces stormed a Catholic church in Baghdad to free dozens of hostages, said Deputy Interior Minister Maj Gen Hussein Kamal.
He suggested six attackers had also died in the fighting, though other sources have said the overall death toll was lower.
Pope Benedict XVI has condemned the "absurd... ferocious violence".
The gunmen had reportedly demanded the release of jailed al-Qaeda militants.
A statement was posted on a militant website allegedly run by the Islamic State of Iraq, a Sunni militant umbrella group to which al-Qaeda in Iraq belongs, claiming responsibility for the attack.
The statement reportedly said Iraqi Christians would be "exterminated" if Muslim women in Egypt were not freed. It specifically mentioned two women in Egypt who radicals believe are being held against their will after converting to Islam.
Residents of Baghdad's affluent Karada district, where the attack took place, first heard a loud explosion at about 1700 (1400 GMT) on Sunday, believed to have been a car bomb going off at the scene.
About 100 people were inside Our Lady of Salvation for an evening Mass at the time.
The blast was followed by gunfire as a group of armed men began by attacking the Iraq Stock Exchange building, police said, and then took over the Catholic church just across the road, clashing with guards and killing some of them.
It seems the church was the attackers' real target, says the BBC's Jim Muir in Baghdad.
One eyewitness, who was inside the church, said the gunmen "came into the prayer hall and immediately killed the priest". The witness, who declined to give his name, said worshippers were beaten and herded into an inne hall.
There was an hours-long stand-off as security forces surrounded the building with helicopters hovering overhead.
The militants made contact with the authorities by mobile phone, demanding the release of al-Qaeda prisoners and also of a number of Muslim women they insisted were being held prisoner by the Coptic Church in Egypt.
But the discussions got nowhere, our correspondent says, and the security forces stormed the church.
Witnesses nearby said they then heard two explosions from inside the church and more shooting. The gunmen reportedly threw grenades and detonated their suicide vests.
Maj Gen Hussein Kamal said 52 "martyrs" had died in the fighting, along with six attackers, though a police source earlier said 37 people - worshippers, security forces and attackers - had been killed.
The number of wounded are put at between 56 and 62 - many of them women.
Pope Benedict XVI denounced the attack as he gave a holiday blessing on Monday. He said two priests had died in the siege, though it was unclear whether both were killed in the initial attempt to take hostages or during the raid by security services.
He said he was praying for the victims "of this absurd violence, made more ferocious because it was directed against unarmed people gathered in the house of God". He called for a new effort to end the violence.
'Impossible to wait'
Iraqi Defence Minister Abdul-Qadr al-Obeidi said security forces approached the building at ground level and from the air. "We took a decision to launch a land offensive, and in addition an airdrop, because it was impossible to wait - the terrorists were planning to kill a large number of our brothers, the Christians who were at Mass," said Mr Obeidi. "So the operation was successfully done. All terrorists were killed. And we now have other suspects in detention."
Witnesses say they saw US troops on the ground and US military helicopters hovering above the scene, but the extent of their involvement is not yet clear.
Many churches have been bombed in recent years - including Our Lady of Salvation in August 2004 - and priests kidnapped and killed, but there has never been a prolonged hostage situation like this before, our correspondent says.
Christians - many from from ancient denominations - have been leaving Iraq in droves since the US-led invasion in 2003, and about 600,000 remain.