Pakistani commandos raided their own army's headquarters Sunday to free 30 people held hostage by Islamist fighters who staged a brazen attack on the compound while wearing military uniforms. Three captives and four hostage-takers were among those killed in the 22-hour-long drama that ended with the capture of the attackers' ringleader, an army spokesman said. The audacious assault on the nerve-center of the country's military establishment showed the strength of militants allied with al-Qaida and the Taliban ahead of a planned army offensive on their heartland in South Waziristan along the Afghan border. It also signaled that any push there would be met with more attacks across Pakistan. The government said the siege had steeled its resolve to go through with the South Waziristan offensive, calling it "inevitable." The United States and Pakistan's other Western allies want the country to take more action against insurgents also blamed for soaring attacks on US and NATO troops in Afghanistan. Explosions and gunshots rang out just before dawn Sunday as commandos moved into a building in the complex, while a helicopter hovered in the sky. Three ambulances were seen driving out of the heavily fortified base close to the capital, Islamabad. Two hours after the raid began, two new explosions were heard. The army said it was "mopping up" the remaining insurgents. Five heavily armed militants took the hostages after they and about four other assailants attacked the main gate of the army headquarters Saturday, killing six soldiers, including a brigadier and a lieutenant colonel. Four of the attackers, who were wearing army uniforms, were killed. No group claimed responsibility, but authorities said they were sure that the Pakistani Taliban or an allied Islamist militant group were behind the strike. The city is filled with security checkpoints and police roadblocks. Army spokesman Maj.-Gen. Athar Abbas said 20 of the hostages had been kept in a room guarded by a militant wearing a suicide vest who was shot and killed before he managed to detonate his explosives. He said the 30 who were ultimately freed included soldiers and civilians. Three captives died, along with four militants, and two of the rescuers, he said. The final hostage-taker was caught later Sunday morning, and he was wounded after trying to set off explosives that he was carrying, Abbas said. Abbas described the captured man as "the leader of all this group." Overall, at least 19 people died in the standoff - six soldiers, two commandos, eight militant attackers and three captives - and several were wounded. Saturday's siege followed a car bombing that killed 49 on Friday in the northwestern city of Peshawar and the bombing of a UN aid agency earlier in the week that killed five in Islamabad. The string of attacks destroyed any remaining hope that the militants had been left a spent force by the death of Pakistani Taliban chief Baitullah Mehsud in a US missile strike in August. A week ago, Baitullah Mehsud's successor, Hakimullah Mehsud, told journalists summoned to a briefing in South Waziristan that the Taliban would launch more attacks on military, government and other targets in the country. The army - which until 2001 had patronized various militant groups for use as proxies in Afghanistan and India - had previously been unwilling to go into Waziristan. Three earlier offensives there have ended in failure, and no one thinks the fight against an estimated 10,000 well-armed fighters there will be any easier this time. But there are hopes the army may have learned from its successful operation in the northwestern Swat Valley this year. Interior Minister Rehman Malik said a Waziristan offensive was now "inevitable." "We are going to come heavy on you," he warned the militants. In its brazenness and sophistication, Saturday's assault resembled attacks in March in the eastern city of Lahore by teams of militants against the visiting Sri Lankan cricket team and a police training center, which the insurgents took over for eight hours before security forces retook it. The attack began shortly before noon when the gunmen attacked the main gate with assault rifles and grenades after bundling out of a white van that reportedly had army license plates. After a 45-minute gunfight, four of the attackers were killed, said Abbas, who initially told the Geo television news channel that the assault was over and the situation "under full control." But more than an hour later, gunshots rang out from the headquarters compound, and Abbas then confirmed that other gunmen had eluded security forces and slipped into the compound. A police intelligence report obtained by The Associated Press on Saturday had warned in July that members of the Taliban along with Jaish-e-Mohammed, a militant group based in the country's Punjab province, were planning to attack army headquarters after disguising themselves as soldiers. The report was given to the AP by an official in the home affairs ministry in Punjab's home department. Officials said Saturday that they had raided a house in the capital where the attackers were believed to have stayed. They found military uniforms and bomb-making equipment. Militants regularly attack army bases across the country and bombed a checkpoint outside the army compound in Rawalpindi two years ago - one of several major bombings to hit the garrison city in recent years. But rarely have the Taliban mounted an armed assault in the city involving multiple fighters.