ISLAMABAD, Pakistan — The 1,800-mile border between Pakistan and India has long been treated as a hostile red line between neighboring, nuclear-armed rivals. Its sole official crossing is a heavily guarded military post. Long stretches are illuminated by powerful floodlights, and the 340-mile, militarized portion that divides the contested Himalayan Kashmir region, known as the Line of Control, has been the site of alpine combat, long-distance shelling and periodic shootings of both Indian and Pakistani border troops.

In contrast, Pakistan’s 1,500-mile border with Afghanistan has always been more porous and politically complicated. Thousands of cargo trucks traverse its two major crossings every week. In the north, where ethnic Pashtun communities straddle both sides of the line drawn by British rulers in 1896, Afghans insist the “real” border lies deeper into Pakistan. They have long accused Pakistani authorities of allowing insurgents to slip across, stage attacks and retreat to safe havens.

Now, with thousands of steel posts and scrolls of deadly razor wire, Pakistan is trying to remove all such ambiguity.

Earlier this week, military officials announced that they are proceeding with a long-stalled plan to build a fence and heighten security measures along the entire border, beginning with the mountainous, semiautonomous tribal regions of Khyber-Paktunkhwa province in the north and gradually extending the work south through the lawless desert badlands of Baluchistan province.

This ambitious project, while unlikely to stop all human traffic, is aimed at sending a tangible signal to Afghanistan, and perhaps more importantly to officials in Washington, that Pakistan is a victim rather than a perpetrator of cross-border terrorism. Building a wall, military officials here assert, is the only way to control a border that has been permeable for far too long.

On Friday, as news spread that terrorists had killed 85 people in scattered attacks across Pakistan that included suicide bombings at both ends of the border, Pakistan’s military spokesman, Maj. Gen. Asif Ghafoor, sent out a terse tweet: “Security/surv[eillance] of Pak-Afg border enhanced. Stringent actions agst illegal Bdr crossers. Recent terrorist incidents linked to sanctuaries across.”

Afghan officials have objected strongly to the new measures, saying they will disrupt normal, necessary cross-border traffic and unfairly punish families and communities on both sides. They also say the actions are unlikely to hinder the cross-border movement of insurgent groups sponsored by Pakistan’s security agencies.

But Pakistan, which routinely denies that it shelters anti-Afghan militants, has also been trying to turn the tables by ramping up accusations against Afghanistan for harboring anti-Pakistan militants — mostly groups driven out of Pakistan by an aggressive military campaign in 2014 and 2015 — and allowing them to set up base camps in tribal areas just inside the border.

In February, when Pakistan was stunned by a blitz of terrorist attacks that killed 125 people, including a suicide bombing at a historic Sufi shrine, the government promptly focused blame on Afghanistan, closed all border crossings and launched a cross-border shelling operation at the northern end against what it said were militant camps used by a group linked to the Islamic State.

Now, Afghan officials are blaming Pakistani-based Taliban militants for a massive bombing in Kabul and other recent attacks, and U.S. officials are considering an economic and diplomatic crackdown on Pakistan unless it takes action to rein in such groups. The army, which is building new border forts and surveillance operations in addition to the fence, says that better border-security management is “in the interest of both countries” and “essential for peace and stability.”

But Afghans aren’t having any of it, saying Pakistan has no right to build such a fence and warning that they may retaliate if the project continues. “In the past, Pakistan made a mistake by constructing buildings along the border and faced strong reaction from us,” said a spokesman for the Afghan Interior Ministry. “We hope they don’t repeat such mistakes again.”

Read more: