Taliban gunmen have stormed a Pakistani air force base, killing at least 17 people, most of whom were offering prayers in a mosque, the deadliest such attack in years.

The assault shows the Taliban retain the capability to mount devastating attacks despite a military campaign and tougher government measures against them following the massacre of more than 150 people at an army-run school last December.

Sixteen of Friday's victims were at morning prayers, and a captain died leading the counter-attack against the raiders, 13 of whom were killed.

Major General Asim Bajwa did not say if those killed in the mosque at the Badaber air base, about six miles south of the centre of the northwestern city of Peshawar, were civilians or military.

"Terrorists entered camp at two points. Encounter began immediately," he tweeted. The attackers "were contained within a close area. Meanwhile a group rushed to mosque, martyred 16 offering prayers."

The attack took worshippers by surprise, said Mohammad Ikram of the Pakistani Air Force, who was in the mosque at the time.

"We were offering prayers when we first heard the gunshots and then, within no time, they entered the mosque where they began indiscriminately firing," he said by telephone from a hospital bed where he was being treated for gunshot wounds.

"They killed and injured most of the worshippers. I fell on the ground. Then the gunmen went to other places in the base. After a long time, we were shifted to the hospital."

A senior Pakistani military official said most of those in the mosque when it was attacked were working with the air force.

"All the terrorists were wearing explosives-laden jackets and were armed with hand-propelled grenades, mortars and AK-47 rifles," a military official at the base said.

Troops were combing villages near the base for any remaining militants, he added.

"We proudly claim responsibility for the attack on Pakistani air base," Taliban spokesman Muhammad Khorasani said, adding that 14 militants had been dispatched to the base. "This base is being used by fighter jets for bombing us."

Attacks by the Taliban have fallen about 70 per cent this year, following a military offensive against the militants' bases along the Afghan border and the government's redoubled efforts to combat them.

Despite the reduction in attacks, the militants still manage to strike high-value targets. The home minister of Punjab province was among 16 killed in a suicide attack last month.

In a separate incident in northwest Pakistan, eight civilians were killed in a military strike in South Waziristan.

"The house next to my house was completely destroyed," said Naimat Ullah, whose son was injured by flying shrapnel.

Neighbours who excavated the bodies had told him three young girls, three men and two women died in the strike, he added.