At least 15 people have been killed and dozens others wounded after a cross-border battle between Pakistani and Afghan forces during a Pakistani population census near the border, officials from both countries said.

The attack on Friday left dozens of people wounded and happened near the Chaman crossing point in Balochistan province prompting security forces to ask people to evacuate villages on the border.

Nine Pakistanis and six Afghans were killed in the clashes, which lasted for several hours.

Chaman, one of the two main border crossings between Pakistan and Afghanistan, was closed in the wake of the incident, with firing ongoing, Pakistani military spokesman Asif Ghafoor said in a statement.

"Since April 30, Afghan Border Police had been creating hurdles in conduct of census in divided villages of Killi Luqman and Killi Jahangir in Chaman area, on Pakistani side of the border," the statement said.

Afghanistan's foreign ministry said it had warned Pakistan against conducting the census in the villages in the border area, which remains disputed between the two countries.

"This area of dispute the imaginary Durand line is not clear and according to the government of Afghanistan the villages (where the clashes happened) are located on the Afghan side of the border. Pakistan claims that these villages are on their side of the Durand line," Ahmad Shekib Mostaghni, spokesman for the Afghan foreign ministry, told Al Jazeera.

"They were warned that they should not conduct the census in the disputed areas and they (Pakistan) have also promised us that they would not conduct the census there," Mostaghni said.

"The violation was committed by Pakistan as the Pakistan armed forces entered the villages of Loqman and Haji Nazar which are located on the Afghan side of the Durand line and areas are elated to the Spin Boldak of Kandahar province. Their defence is the duty of the Afghan national defence forces," he added.

Pakistan census

Pakistan is currently conducting the second phase of its first door-to-door population census in 19 years, with more than 100,000 enumerators and 200,000 troops taking part in the exercise.

The lead-up to the census has been marked by political debate on how the results may show changing demographics - potentially redrawing electoral constituencies - across the country.

Recent Pakistani attempts to establish fences and border posts along the border to curtail the movement of Taliban fighters into Pakistan have been met with resistance from Afghanistan, which disputes the border.

In February, Pakistan sealed all border crossings with Afghanistan for over a month after a wave of attacks across Pakistan killed more than 100 people.

Those attacks were followed by frequent skirmishes between Pakistani Taliban fighters and Pakistan's military along the border in the Mohmand, Khyber and other districts.