After the other British left, Mr. Langlands stayed on, taking a teaching job at Aitchison College in Lahore, Pakistan’s most prestigious boarding school. Over a quarter-century there, he imparted algebra to the offspring of the Pakistani elite, some of whom went on to lead in politics, sports and the military. Former charges include Zafarullah Khan Jamali, who was prime minister between 2002 and 2004, and Imran Khan, the cricket hero turned politician.

“He stood out,” Mr. Khan said. “He had this mixture of being firm yet compassionate.”

In 1979, he moved to North Waziristan, in the tribal belt, to run a school in a district that is today better known for American drone strikes — Al Qaeda’s deputy leader was reported killed there on Monday.

Mr. Langlands, however, remembers the tribesmen as rascals more than villains. At one point, he said, tribesmen held him hostage for six days in a bid to overturn an unfavorable election result. It did not work, but his captors treated him decently, even insisting he join them for some rifle practice.

“It wasn’t so bad,” he said with a soft chuckle. “They were very polite once they found out I was 71. And before I left, they insisted on having their photo taken with me.”

In Chitral, life is quieter. In the northern corner of Khyber-Pakhtunkwa Province, it has escaped the Taliban firestorm thanks to its geographic and cultural isolation. The spiked peaks of the Hindu Kush are a formidable palisade, although an insurgent attack on the Afghan border last year jangled nerves. Unlike most of the surrounding region’s people, the Chitralis are not ethnic Pashtuns, and their passions lie with playing a rambunctious version of polo (imagine rugby on horseback), educating their children and cutting loose.

During the recent gathering to install a hereditary tribal prince, things became typically raucous: tipsy young men danced wildly in celebration as they took gulps from a bottle of moonshine, watched quietly by police officers.

Mr. Langlands is in some respects the quintessential Englishman of old, a living relic of the Raj. He lives in a ramshackle little cottage in the town center, where he rises every morning at 5:40. Exactly 40 minutes later, a servant appears with breakfast: oatmeal, a poached egg and two cups of tea, always. Mr. Langlands flicks through the latest newspaper, which, given the valley’s erratic plane service, may be several days old.