BANNU, Pakistan -- A Taliban bombing inside an army compound in northwest Pakistan killed at least 20 troops Sunday, officials and militants said, in one of the deadliest attacks to target the country's forces as they battle insurgents in its volatile frontier.

The blast targeted a vehicle in a convoy about to leave a military base in the town of Bannu and drive west to the North Waziristan tribal area, police official Inyat Ali Khan said. Pakistan's military said the blast wounded 30 troops.

The Taliban claimed the attack and called it a suicide bombing. Military officials said the blast came from an explosive planted in the vehicle, hired by the paramilitary Frontier Corps. While the army has its own transport vehicles, the paramilitary forces often hire vehicles when they need to move troops in large numbers.

A spokesman for the Pakistani Taliban, Shahidullah Shahid, told The Associated Press by telephone that the attack had been carried out to avenge the death of Waliur Rehman, the group's former second in command. He was killed last year in a U.S. drone strike.

"We will avenge the killing of every one of our fellows through such attacks," the spokesman warned.

The explosion was heard and felt across the town of Bannu.

"I rushed out of my home and saw black, thick smoke billowing out of the cantonment's Razmak gate area," resident Sajjad Khan said. He said troops quickly cordoned off the area and ordered residents to go back inside their homes.

North Waziristan is considered a safe haven for al-Qaida-linked militants. Pakistani troop convoys often are hit by roadside bombs, but blasts inside military compounds are rare.

Last December, a suicide bomber killed four Pakistani soldiers when he rammed an explosive-laden car into a checkpoint outside an army camp in North Waziristan. Thirty Pakistani troops died over a four-day period last April in another part of the northwest called the Tirah Valley as part of an operation to oust militants hiding there.

The Pakistani military has been fighting for years in the tribal areas against militants who want to overthrow the government and establish a hard-line Islamic state. The tribal region is also a refuge for insurgents fighting NATO and U.S. forces in neighbouring Afghanistan.

Many Pakistanis resent fighting fellow Muslims and have grown tired of the long war. Many see it as having been foisted upon them by the U.S. after the Sept. 11, 2001, terror attacks and the invasion of Afghanistan.

Prime Minister Nawaz Sharif, elected last May, has promised to end the fighting through peace talks. But so far the Pakistani Taliban has shown little desire to negotiate with the government and ruled out talks after a U.S. drone strike killed leader Hakimullah Mehsud on Nov. 1. Previous attempts at talks quickly failed.

In their statement Sunday, the Taliban said it would be open to talks but only if they thought the government was sincere.

The militants have accused Pakistan of helping the U.S. target Mehsud. Islamabad vehemently denied the allegation and accused Washington of sabotaging the nascent peace talks.

Mehsud's replacement, Mullah Fazlullah, is not seen as a supporter of peace talks. Fazlullah is known as a particularly ruthless militant who planned the failed assassination targeting teenage activist Malala Yousafzai in 2012.