But in recent months, there have been increasing reports that some Pakistani Taliban fighters have managed to come back to some of the tribal areas in the northwest. Last Monday at least three people, including a Pakistani colonel, were killed in a shootout between soldiers and militants in Tank district, near South Waziristan.

Fence construction groups have also been attacked by militants, who have released videos of themselves tearing down sections and seizing building supplies.

Corruption and bribery are also likely to help people find ways through in a region where smuggling has been a way of life for many.

The fence may slow down illegal crossings, but it will not stop them entirely, said Elizabeth Threlkeld, an American diplomat in the border city of Peshawar until 2016 and now with the Stimson Center, a Washington-based think tank that focuses on foreign policy.

“Many of those determined to cross, including both militants and local residents whose livelihoods depend on smuggling, will find a way,” Ms. Threlkeld said. “The greater impact of the fence will instead be on Pashtun communities spanning the border, who will lose the ability to cross freely to visit family or do business.”

Cross-border trails and roads were once common in the mountains on either side of Torkham, many of them without checkpoints.

Zahid Shinwari, a former chairman of the chamber of commerce for Khyber Pakhtunkhwa Province, where the Torkham crossing is, said that traders bound for bazaars, or families visiting relatives, had thought little of the frontier and were used to passing without paperwork checks.