Observers saw the Taliban's takeover of Afghanistan last year as a strategic victory for neighboring Pakistan after years of frosty relations between Islamabad and the Western-backed government in Kabul that collapsed last August. Security concerns along the two nations' border have since complicated the picture.
Many Pakistanis celebrated the Taliban's return to power, including Prime Minister Imran Khan, who declared that Afghans had broken the "shackles of slavery."
Some Pakistanis also welcomed a perceived blow to archrival India, which had close ties with the former Afghan government.
In the weeks that followed, Pakistan launched a diplomatic effort urging the international community to engage with the Taliban, help ease Afghanistan's humanitarian crisis and prevent it from descending into chaos again. For the first time, Pakistan even allowed India to transport humanitarian aid to Kabul through Pakistani territory.
In December, foreign ministers of the 56 nations belonging to the Organization of Islamic Cooperation, along with Taliban and U.S. delegates, gathered in Islamabad. The meeting focused on Afghanistan's humanitarian crisis.
Despite such efforts, tensions have sometimes flared between Islamabad and Kabul, to the surprise of many in the region. Pakistan has complained of cross-border terrorist threats originating in Afghanistan since the Taliban came to power.
The Pakistani offshoot of the Afghan Taliban, known as Tehrik-i-Taliban Pakistan (TTP) or the Pakistani Taliban, has intensified attacks inside Pakistan from bases across the Afghan border, killing dozens of security forces in recent months.
On Sunday, heavy gunfire from inside Afghanistan targeted a northwestern Pakistani border post, killing five soldiers. The TTP took responsibility.
"Pakistan's principal concern at this juncture is terrorism emanating from Afghan soil, of which it has been a victim in the last many years," said Raoof Hasan, a special assistant to Khan.
"We are interacting closely with the Afghan authorities for formulating a coordinated and effective approach. We can't afford to remain a hostage of these terrorist forces," Hasan told VOA.
Pakistani security officials say that following the withdrawal of U.S. and allied forces from Afghanistan, TTP insurgents apparently enjoy greater operational freedom and mobility in the country.
U.S. drone attacks and Afghan military operations had killed dozens of TTP militants over the years. Earlier this month, the United Nations estimated between 3,000 and 5,000 Pakistani Taliban are in Afghanistan.
Pakistani officials believe the Afghan Taliban have turned a blind eye to TTP activities since returning to power. Further inflaming tensions, the Afghan Taliban tried to stop Pakistani troops from erecting a security fence along the roughly 2,600-kilometer common border to deter terrorist infiltration.
Afghanistan has never accepted the border demarcation with Pakistan drawn up by 19th-century British colonial rulers. The border controversy has been an emotional issue for Afghans and a source of mutual tension irrespective of who is in power in Kabul.
But analysts say the Taliban, often branded as close allies of Pakistan, are taking a visibly hostile approach in a bid to win praise from Afghan nationalists and enhance their domestic legitimacy.
In video comments on Twitter, a Taliban Defense Ministry spokesman said that "Pakistan has no right to fence the border and divide [ethnic] Pashtuns living on either side of the border."
The Taliban reject allegations that their territory is being used against Pakistan and have repeatedly pledged to disallow terrorist groups from launching attacks against other countries from Afghan soil.
While U.S. and former Afghan government leaders accused the Pakistani military of covertly supporting the Taliban insurgency in Afghanistan, the TTP — designated a global terrorist group by the U.S. and United Nations — provided recruits and safe havens on Pakistani soil for the Afghan Taliban.
Afghan Taliban rulers now appear to be returning the favor by refusing to evict TTP leaders from Afghan soil or crack down on their activities, as Pakistan has requested.
Instead, the Taliban advised interlocutors in Islamabad to engage in peace talks with the extremist group. The Afghan Taliban mediated a 30-day truce between the TTP and the Pakistani government in November as a "confidence-building measure" for reconciliation talks.
But the process fell apart in early December, and the TTP has resumed deadly attacks on Pakistani forces.
The Afghan Taliban told Pakistan that the TTP fought alongside them for 20 years in Afghanistan, Pakistani Interior Minister Sheikh Rashid Ahmed told Pakistani lawmakers when discussing Kabul's hands-off approach to the TTP.
This has reportedly compelled Pakistan to retaliate covertly against TTP leaders in Afghanistan, including targeting them with drone attacks. Several key members of the group have been killed in Afghan border provinces in recent weeks, but there have been no claims of responsibility.
The TTP has taken credit for killing thousands of people in Pakistan, including security forces, in suicide bombings and other attacks over several years.
Even so, officials in Islamabad note that the Taliban have only recently returned to power after two decades and face serious governance and financial challenges.
"It was a natural expectation that there would be a considerable reduction in incidents of violence in Pakistan undertaken by [Afghan-based] groups such as TTP," said a senior Pakistani official who has taken part in recent bilateral meetings with Taliban leaders in Kabul. The official wished to remain anonymous because he was not authorized to speak to journalists.
"But this is not happening, and it means that those groups continue to receive support and funding from somewhere. That is a cause of serious worry for Pakistan," he said. "We are having a very frank engagement with them on this issue. They are aware of the troublemakers in Afghanistan, but they also tell us it would require time, patience and understanding to deal with this issue."
Pakistani officials say they have told the Taliban government that Islamabad will extend diplomatic recognition only after other nations do so. In their view, how Afghanistan's Islamist rulers deal with the TTP will serve as a test case for their counterterrorism pledges to the broader international community.
Pakistan and China are encouraging the Taliban to forge an international counterterrorism framework to ensure terrorist groups do not have operational freedom in Afghanistan, diplomatic sources privy to the discussions told VOA.
A U.N. terrorism monitoring report released last week said the Taliban had failed to take "steps to limit the activities of foreign terrorist fighters in the country."
The report added: "On the contrary, terrorist groups enjoy greater freedom [in Afghanistan] than at any time in recent history."
The Taliban Foreign Ministry rejected the U.N. findings, saying, "Afghanistan is witnessing exemplary security since the Islamic Emirate regained full sovereignty over the country." Islamic Emirate is the official name of the Taliban government.
Pakistan was one of three countries, including Saudi Arabia and the United Arab Emirates, to recognize the Taliban government in the late 1990s.
Michael Kugelman, the deputy director of the Asia program at the Washington-based Wilson Center, said Islamabad had received a "rude awakening" from the cross-border attacks from Taliban-held Afghanistan.
"These attacks, coupled with the Taliban's desire to be sure that Afghans don't perceive the group to be doing Pakistan's bidding, have generated tensions. But at the end of the day, the relationship will endure," Kugelman said.
"The Taliban is Pakistan's ticket to influence and access in Afghanistan. And Pakistan is a critical diplomatic backer of the Taliban. In effect, despite tensions, both sides need each other, and that means we shouldn't expect a rupture."
In a report released this month, the International Crisis Group said Pakistan faces difficult challenges in shaping policy toward the Taliban in Afghanistan, but it predicted Islamabad would maintain close ties with the regime.
In doing so, Pakistan has an opportunity to do some good, according to the ICG.
"It should use those ties carefully, to nudge the Taliban toward compromises on governance, including on respect for basic rights and adherence to counterterrorism commitments that might win them greater favor abroad and help ease Afghanistan's humanitarian tragedy," the ICG report said.