Military Spokesman Major General Athar Abbas said the commandos have freed 25 hostages and killed four terrorists, including some who were wearing suicide jackets.
He said three of the hostages also died during the operation. Abbas did not give details about casualties among the troops who had carried out the final assault.
Commandos of the elite Special Service Group carried out the operation to free the hostages, a few minutes before 04:00 pm.
Several explosions were heard after the troops launched their assault.
The hostage crisis began on Saturday when a group of about 10 terrorists tried to storm the army's General Headquarters. The terrorists initially killed six soldiers, including a Brigadier and Lt Colonel.