The raid came a day after a suicide bombing at a Shiite Muslim mosque elsewhere in the northwest that killed 24 people, police said. The blast at the mosque was the latest in a rising number of sectarian attacks in the country.

The Pakistani Taliban claimed responsibility for both attacks. The group has been waging a bloody insurgency against the government for years and sometimes targets the country's minority Shiites.

The Taliban and allied militant groups have stepped up the pace of attacks in Pakistan in recent months, an indication of their strength despite numerous army operations against their strongholds in the northwest.

The raid on the army post in Serai Naurang town of Khyber Pakhtunkhwa province began around 3:45 a.m. local time and lasted for several hours, said senior police officer Arif Khan Wazir. The militants fired automatic weapons and rocket-propelled grenades, he said.

Two security officials said the militants killed 10 civilians, including three women and three children, in a nearby house. In addition to the civilians, nine soldiers; four members of the Frontier Constabulary, a force that polices parts of northwestern Pakistan; and 12 attackers also were killed in the fighting.

Both officials spoke on condition of anonymity because they were not authorized to talk to the media.

Pakistani Taliban spokesman Ahsanullah Ahsan claimed responsibility for the attack in a telephone call to The Associated Press from an undisclosed location. He said four suicide bombers were involved in the attack. He said that three of them were killed and the fourth was still resisting as of his call at around 9:20 a.m. local time.

Ahsan said the attack was in retaliation for the recent deaths of two Taliban commanders in U.S. drone strikes. He accused the Pakistani army of helping with the attacks. Pakistani officials often criticize drone operations as a violation of the country's sovereignty, but are known to have assisted some U.S. strikes in the past.

A police official, speaking on condition of anonymity because he was not authorized to brief the media, said he saw the bodies of three attackers with their suicide vests intact. Their features suggested they belonged to a group of Uzbek militants allied with the Taliban, he said.