PESHAWAR, Pakistan — Pakistan’s army and intelligence chiefs traveled to Afghanistan on Wednesday to seek help locating the Pakistani Taliban commanders responsible for the massacre of students at a school here in Peshawar the day before, officials said.

The trip, by Gen. Raheel Sharif and Lt. Gen. Rizwan Akhtar, the head of the Inter-Services Intelligence spy agency, was described by officials of both countries as an effort to find common ground.

The two neighbors have for years had an uneasy relationship, and tensions have frequently flared over cross-border attacks by militants — although usually ones on Afghan soil by militants sheltering in Pakistan. In particular, the Pakistani military’s history of support for the Afghan Taliban has long been an irritant for Afghan officials.