A shootout in a northwestern region of Pakistan near the Afghanistan border early Sunday left four soldiers and four militants dead, Pakistan's military said.

A statement from the military's public relations wing said the exchange of fire in North Waziristan took place after the army personnel had surrounded the militant hideout early Sunday.

"As soon as the troops cordoned off the area, terrorists opened fire. All dug out terrorists were shot down by security forces, " the statement said. "In exchange of fire, four soldiers embraced shahadat (martyrdom)."

The militants were not identified, but Pakistan's military has been battling members of the Pakistani Taliban group, known as the Tehreek-e-Taliban (TTP) in North Waziristan for years.

MAN WHO BEHEADED US JOURNALIST DANIEL PEARL, 3 OTHERS LINKED TO CRIME WILL REMAIN IN JAIL – FOR NOW

TTP, which has also voiced support for the Islamic State in Afghanistan, declared war on the government of Pakistan more than a decade ago. Since then, they have carried out a series of attacks, including a brutal assault on a Pakistan Army Public School in northwest Peshawar in December 2014, killing 140 children and several teachers.

CLICK HERE TO GET THE FOX NEWS APP

Pakistan's militant groups are often interlinked with those across the border in Afghanistan, so its progress at reining in terror is critical, particularly as Washington seeks to forge ahead on an agreement with the Afghan Taliban to bring an end to the 18-year war.

The Associated Press contributed to this report.