Government troops stormed Islamabad's Red Mosque on Tuesday, killing at least 50 militant rebels. Eight soldiers were also killed in the raid that began just after dawn.
The militants were accused of holding some 150 hostages inside the compound.
Army spokesman General Waheed Arshad said that soldiers attacked the mosque from three directions about 4 am and quickly cleared the ground floor.
Twenty children rushed toward the advancing troops and were brought to safety, he said.
Twenty-four others fleeing the compound were captured by security forces.
"Those [rebels] who surrender will be arrested, but the others will be treated as combatants and killed," Arshad said.
The assault began minutes after failed talks between rebel leader Abdul Rashid Ghazi and a delegation led by former Prime Minister Chaudhry Shujaat Hussain.
Hussain was asked by President General Pervez Musharraf on Monday to negotiate a peaceful end to the standoff but after nine hours of talks via loudspeakers and mobile phones, Hussain announced that efforts had failed.
"We offered him a lot, but he wasn't ready to come on our terms," Hussain told reporters waiting at the edge of the army cordon.
The siege of the Red Mosque was prompted by clashes between security forces and supporters of the mosque's hard line clerics.
The religious extremists were calling for Taliban-style morality in the capital through a six-month campaign of kidnappings and threats. At least 67 people were killed since July 3.