Pakistani students in Lahore pray during a special ceremony for the victims of Tuesday's school attack in Peshawar. (K.M. Chaudary/AP)

As the death toll rose to 148 from Tuesday’s massacre at a military-funded high school, the crisis sent Pakistani leaders rushing to Kabul on Wednesday to make a rare request for Afghanistan’s help in fighting Islamist terrorism on both sides of their volatile border.

After years of mistrust and enmity, it was a moment of truth for the neighboring Muslim countries, both facing new bouts of terrorism that threaten to reinforce their mutual suspicions and ignite more violence as Western forces finalize their withdrawal from Afghanistan. Yet the moment also offered an opportunity to replace finger-pointing with something closer to common cause.

In Pakistan, officials hinted that the Taliban militants who attacked the school in the northwestern city of Peshawar had been based in the Afghan tribal belt. Prime Minister Nawaz Sharif, on a visit to Peshawar, vowed to pursue militants beyond Pakistan’s borders and said his government “will not rest until every terrorist is killed.”

The prime minister, facing public pressure to take tough measures after the school attack, also approved a committee’s decision to lift Pakistan’s 2008 moratorium on the death penalty, officials said. Pakistan has about 9,000 prisoners on death row, including about 900 convicted on terror-related charges.

Ashraf Ghani, the recently inaugurated Afghan president, appeared to agree that action could be taken on Afghan soil against suspects from the Pakistani Taliban. He seemed unlikely, however, to allow Pakistani forces to pursue them there, given the history of bilateral tensions and clashes along the porous border.

The hastily arranged meeting in Ghani’s palace included Gen. Raheel Sharif, Pakistan’s army chief, and Gen. John F. Campbell, commander of the U.S.-led coalition forces here. Afterward, Ghani issued a statement saying, “Now is the time for Afghanistan and Pakistan to act honestly and effectively with each other to fight against terrorism.”

Calling the assault on the Pakistani school an attack on “Afghans and Muslims everywhere,” Ghani declared that the perpetrators were “the same ones who attacked our children” in a suicide bombing last month at a volleyball match in Afghanistan’s Paktika province that killed more than 45 people.

Gen. Sharif expressed optimism that both Ghani and the coalition will help target Pakistani Taliban leaders who take refuge across the border. A military statement said that the general and his aides had shared “vital elements of intelligence” with the Afghan leader about the Peshawar attack and that Ghani had promised to prevent Afghan soil from being used for terrorist activities.

Some analysts and social media users in Afghanistan expressed deep suspicion about Pakistan’s motives and warned Ghani not to trust its leaders. Many Afghans — including former president Hamid Karzai — are convinced that Pakistan’s intelligence service has been behind many terrorist attacks in Afghanistan in recent years, including a dozen in the capital over the past month.

It is also widely believed among Afghans that Pakistan and its security establishment seek to dominate their poorer and weaker nation and to use it as a source of strategic depth in countering the regional influence of Pakistan’s arch rival, India.

Atiqullah Amarkhail, a retired Afghan army general in Kabul, dismissed Gen. Sharif’s visit as an attempt to distract attention from Pakistan’s failure to prevent the school attack. He called it a “maneuver” to pressure Ghani’s government and “pretend those responsible for the deadly attack in Peshawar are based in Afghanistan.”

“Pakistan will never give up destabilizing Afghanistan,” said one Afghan, Fatel Arezoi, in a Facebook post Wednesday night. “Gen. Raheel is here to get support from the Afghan army to destroy the TTP [Pakistani Taliban]. . . . Do not help him. The TTP is Pakistan’s problem, not ours.”

In Pakistan, prayer vigils were held across a nation in shock and mourning after the unprecedented attack, in which seven Taliban gunmen and suicide bombers stormed the school, then systematically gunned down scores of teachers and students before being killed by army commandos after a lengthy battle.

Amid the outpouring of national grief, there were signs that the attack had temporarily united Pakistan’s political opposition behind Nawaz Sharif and the military. On Wednesday night, politician Imran Khan announced that his Movement for Justice party was ending its four-month protest campaign against the Sharif government.

The army’s chief spokesman, Maj Gen. Asim Bajwa, hinted that army officials know where the attack was orchestrated. He did not specifically blame militants living in Afghanistan, but he refused to rule out a cross-border military operation to try to capture or kill more Pakistani Taliban leaders.

It has been widely reported that Pakistani Taliban leaders use Afghan tribal areas as hideouts, just as the Afghan Taliban has long used Pakistan as a base. They share a common religious agenda but operate separately. An Afghan Taliban spokesman Tuesday condemned the Peshawar school bombing, as did some Islamist groups in Pakistan.

Until now, despite years of terrorist attacks, Pakistan’s military and intelligence establishment has remained ambivalent about taking on the domestic Islamist fighters, in part because they function as proxies in Pakistan’s 50-year rivalry with India and in part because they are popular with many Pakistanis.

A Pakistani military official, who spoke on the condition of anonymity, said that one of the militants killed at the school had “well-established” links to Pakistani Taliban leadership in Afghan border areas and that officials had traced phone calls back to Afghanistan.

A spokesman for the Pakistani Taliban, formally known as ­Tehrik-e-Taliban Pakistan, issued a statement describing the assault on the school, naming the commanders involved and laying out the group’s motives. The statement declared that for the past six years, Pakistan’s “evil army has been targeting innocent Muslims” in the tribal areas and had killed thousands of them in military raids .

“Due to this historical injustice,” the statement said, the militant group was “forced to take the extreme step” of attacking a school where the sons of army officers were studying. It demanded that the “genocide” of tribal Muslims be stopped, as well as the arrests and killings of militants’ relatives. Otherwise, it warned, the Pakistani Taliban would be “forced to attack all organizations associated with the security forces.”

Craig reported from Peshawar. Haq Nawaz Khan in Peshawar and Shaiq Hussein in Islamabad contributed to this report.