Suspected Taliban militants wearing army uniforms attacked the Pakistani army's headquarters killing six soldiers and triggering a battle in which four gunmen died, military officials said.

The attack on the tightly-guarded headquarters in the city of Rawalpindi came as the army prepares a major offensive against Pakistani Taliban militants in their north-western stronghold on the Afghan border.

The gunmen drove in a white van to a main gate at the complex, and opened fire and threw at least one grenade when challenged, security officials said.

The gunmen then exchanged fire with soldiers for about 40 minutes.

Six soldiers, including a brigadier and a lieutenant-colonel who were passing through the gate, were killed.

Four gunmen died but two escaped. Security forces later tracked the two gunmen down, a military spokesman said.

The attack came a day after a suspected suicide car-bomber killed 49 people in the city of Peshawar in an attack the government said underscored the need for the all-out offensive.