With public sentiment rising against terrorism, the Pakistani and Afghan governments have decided to abandon their traditional policy of giving terror groups shelter in exchange for a promise not to carry out attacks inside the “host” nation.

As a result of that policy, a variety of terror groups have been able to set up bases in the two neighboring countries, at times in full view of the authorities.

The Pakistani Taliban attack Pakistan from bases in Afghanistan, and the Afghan Taliban operate from bases in Pakistan.

Last week, however, Pakistan army chief Gen. Raheel Sharif and his Afghan counterpart, Shir-Muhammad Karimi, signed an agreement that may well signal a strategic change in the two nations’ methods of dealing with terrorism.

Under the agreement, the two neighbors will allow each other’s forces the right of hot pursuit.

This had been a thorny issue for decades, as successive Afghan governments refused to recognize the border fixed by the British during their rule in the Indian Subcontinent.

Afghans claim that large chunks of land, where Pushtun tribes form a majority, represent “Afghan occupied territory ” that should return to “the motherland,” a position firmly rejected by Pakistan.

Right now, some terror bases operating against Afghanistan are located just a couple of miles inside Pakistani territory under protection of Pakistani border guards.

With the new agreement, that protection will no longer be available. In fact, last week an Afghan unit pursued a terrorist group inside Pakistani territory for the first time.

The agreement also envisages an exchange of information on a regular basis. That would enable both neighbors to learn about planned attacks in time to deal with them.

Up to now, terror groups have been able to travel hundreds of miles with full knowledge of Pakistani security services to carry out attacks in Afghanistan.

A mere tip on their movements could have saved thousands of lives. The Afghans have repaid the compliment by keeping the Pakistanis in the dark about the movements of the Pakistani Taliban.

Although it is welcome, the agreement remains imperfect if only because it is vague on a number of crucial issues. For example, it says nothing about the presence of terror leaders, often in full public eye.

The top echelon of the Afghan Taliban’s leadership, after all, is located in nine large houses in the Pakistani city of Quetta. The group, calling itself “the Quetta Shura” or council, holds plenary sessions four times a year, often posting parts of the proceedings on YouTube.

It is also there that Mullah Muhammad Omar, the self-styled “Commander of the Faithful,” holds court, receiving local and foreign visitors. His secretariat reportedly employs more than two dozen individuals, including several Pakistani IT experts.

The Afghans return the favor by allowing the leader of the Pakistani Taliban, Mullah Abdul-Razzaq, full facilities to run his headquarters in Jalalabad, close to the disputed border with Pakistan.

Both Islamabad and Kabul try to justify their strange behavior by claiming they are allowing the Taliban nothing but “normal political activity.”

In other words, the Taliban’s terrorist activities should be treated separately from the “exercise of their freedom of expression and assembly.”

The United States could and should play an active role in cementing the new agreement and helping address its shortcomings.

Since the US is actively involved in the war on terror in Afghanistan, it would only be normal if it coordinated at least some of its operations with Afghan and Pakistani security forces.

With Kabul and Islamabad having agreed to set the thorny issue of borders aside for the time being, the United States should no longer automatically rule out the targeting of terror groups fleeing from Afghanistan into Pakistani shelters or vice versa.

Washington could also cajole Afghanistan and Pakistan into agreeing on a common list of terrorist entities.

Such a list would remove the excuse that a group could be terrorist in one country and merely political in another. The idea is that one man’s terrorist is every man’s terrorist.

Further down the road, Afghanistan, Pakistan and the US may even envisage setting up a joint coordination mechanism, at least on an informal basis.

All three nations have been victims of terrorism and continue to be targeted by terrorists often based in “ungoverned areas” straddling Afghan-Pakistani borders.

Though it’s too early to know whether Kabul and Islamabad are truly committed to eradicating terrorism, the US must not miss the opportunity created by a massive turn in public opinion in both countries against terror and Islamism in general.