PESHAWAR, Pakistan — A raid on a suspected militant hideout in northwestern Pakistan early on Tuesday morning killed five anti-terrorism commandos and two militants, the police said.

According to police spokesman Imtiaz Khan, a blistering firefight erupted when the commandos tried to raid a house in the Chilas district, 460 kilometers (285 miles) north of Peshawar, the capital of Khyber Pakhtunkhwa province which borders Afghanistan.

The fighting lasted several hours, Khan said. Along with the two militants killed, a cache of weapons and explosives was recovered, he added. It wasn't immediately known which militant group was involved in the firefight. The Pakistani Taliban — the Tehreek-e-Taliban Pakistan or TTP — are active in the province.

Pakistan alleges that militants from the outlawed TTP have found safe havens in Afghanistan. A U.N. report released last week says that more than 6,000 Pakistani militants are hiding in Afghanistan, the majority of them from the TTP, which has also aligned with the Islamic State group based in Afghanistan.

The U.N. report said the TTP and the IS affiliate pose a serious threat to both Pakistan and Afghanistan. In 2018, the group set fire to 14 schools for girls in the area; police arrested more than 35 militants suspected of involvement in the attack.