Military officials in Pakistan say the siege near the army's headquarters in Rawalpindi near the capital, Islamabad, is over.
The military said Sunday commandos stormed the building and freed 25 hostages held since Saturday morning when militants attacked the army headquarters.
Army spokesman Major-General Athar Abbas said three captives, four militants and two soldiers were killed during the morning rescue operation Sunday.
Gunmen in military camouflage attacked the headquarters Saturday, killing six soldiers during a gunbattle at the main gate. Four attackers were also killed. Two others were captured, but several gunmen fled and took hostages in a nearby office building.
No group has claimed responsibility. But Pakistani leaders blame the Taliban for Saturday's attack, and have vowed to start a new offensive against militants in the South Waziristan tribal region.
Gunfire and explosions could be heard from inside the headquarters early Sunday, as security forces moved into the building. Abbas said most of the hostages were in a room guarded by a militant wearing a suicide vest. Troops killed him before he could detonate his explosives.
U.S. Secretary of State Hillary Clinton told reporters Saturday's attack shows the continuing threats to the Pakistani government and the important steps the civilian leadership and military are taking to root out extremists and prevent violence.
On Friday, at least 50 people died in a suicide bombing in the northwestern city of Peshawar. And the Taliban claimed responsibility for a suicide attack last week on a U.N. building in Islamabad that killed five people.
Some information for this report was provided by AFP, AP and Reuters.