The assault in Islamabad was part of a wave of bloodshed that has killed more than 170 people in Pakistan over the past three weeks and pushed the military into launching a long-anticipated ground offensive in South Waziristan tribal region six days ago.
The offensive is considered a critical test of Pakistan's campaign against Islamist extremists aiming to overthrow the state and involved in attacks on Western forces in neighboring Afghanistan.
The gunmen fired on an army jeep in a residential area, police official Zaffar Abbas said. A soldier and a brigadier -- a high-ranking army officer -- died, while the soldier driving the car was wounded, said Waseem Khawja, a hospital official.
Footage on private Express TV channel showed the bulletholes splattered on the green jeep's windshield.
No group immediately claimed responsibility, but the Pakistani Taliban, the target of the offensive, have said they were behind several recent attacks on security forces, including a siege of the army's headquarters.
The military is advancing on multiple fronts in South Waziristan, one of the places Al-Qaeda chief Osama bin Laden is rumored to use as a hideout. Over the past few days, they have been fighting for the hometown of Pakistani Taliban chief Hakimullah Mehsud.
An army statement on Wednesday said forces were engaged in "intense encounters" in hills surrounding Kotkai and had secured an area to its east. Two intelligence officials said troops had secured parts of the town and destroyed Mehsud's house, but army spokesman Maj. Gen. Athar Abbas denied that late Wednesday, saying there was no significant fighting inside the town yet.
The army believes Mehsud and his deputy Qari Hussain remain in the region directing militants' defenses.
The statement Wednesday reported three more soldiers were killed, bringing the army's death toll to 16, while 15 more militants were slain, bringing their death toll to 105.
It is nearly impossible to independently verify information coming from South Waziristan because the army has closed off all roads to the region. Analysts say both sides have exaggerated successes and played down losses in the past.
The army has deployed some 30,000 troops to South Waziristan against about 12,000 Taliban militants whose ranks include up to 1,500 foreign fighters, many of them Uzbeks.
Get Breaking news, live coverage, and Latest News from India and around the world on NDTV.com. Catch all the Live TV action on NDTV 24x7 and NDTV India. Like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.