Pakistan's army chief General Raheel Sharif

Reuters/Kabul

Pakistan's army chief and the head of its main intelligence agency flew to neighbouring Afghanistan on Wednesday to seek help in battling the militants behind this week's school massacre in Pakistan in which 148 people were killed.

"The time has arrived for Afghanistan and Pakistan to act together against terrorism and extremism with honesty and effectiveness," Afghan President Ashraf Ghani said in a statement. Pakistan said it had shared intelligence with Ghani.

Pakistan-Afghanistan relations have been tense for years, each accusing the other of backing anti-government militants.

Pakistani army chief General Raheel Sharif and the head of its Inter-Services Intelligence agency, Rizwan Akhtar, met Ghani, the president's office said after the surprise trip.

Neither side disclosed details, including whether Ghani demanded Islamabad sever ties with Mullah Omar, the leader of the Afghan Taliban.

"We are hoping that we will see strong action from the Afghan side in the coming days," Pakistani army spokesman Major General Asim Saleem Bajwa said, adding that the new leadership in Kabul had shown it was willing to act.

Pakistani complaints of Afghanistan failing to act against anti-Pakistan militants come after years of Afghan accusations that Pakistan was backing the Afghan Taliban.

Pakistan backed the Afghan Taliban when it rose to power in the 1990s. Their regime was toppled by a US invasion in 2001.

Despite denials of support, Pakistan is widely believed to see the Afghan militants as a tool to limit the influence in Afghanistan of its old rival, India.

Angered by what it see as years of Pakistani encouragement for the Afghan Taliban, Afghanistan - Pakistani security officials believe - has been quietly supporting Pakistani Taliban militants fighting Islamabad. Afghanistan denies that.

How Afghanistan responds to Pakistan after Tuesday's killing spree in Peshawar will be a major test of their relations.

Afghanistan, aided by US drone strikes, has in recent weeks stepped up operations against anti-Pakistan militants on its side of the border, and did not oppose the US transfer of a top Pakistani militant, Latif Mehsud, to Pakistan last week.

Afghan troops were on Wednesday battling hundreds of militants in the eastern province of Kunar, on the border with Pakistan, for a fourth day, the Afghan army said. It said 40 militants had been killed.

Afghan authorities said earlier most of the militants were Pakistani Taliban.

The Afghan Taliban and the Pakistani Taliban are allied but separate forces.

Related Story