Geoffrey D. Langlands, a British officer who stayed in Pakistan after his military service ended and became one of the country’s most celebrated educators, died on Wednesday at a hospital in Lahore. He was 101.

His death was confirmed by Aitchison College, Pakistan’s most prestigious boarding school, in Lahore. Mr. Langlands spent 25 years there as a teacher and later a headmaster.

In more than six decades of teaching mathematics and English, sometimes in regions rife with violence, Mr. Langlands, commonly known as “the Major,” guided the children of Pakistan’s elite to top careers. His students included Zafarullah Khan Jamali, a former prime minister, and Imran Khan, the current prime minister.

“He stood out,” Mr. Khan said of Mr. Langlands, the subject of a Saturday Profile in The New York Times in 2012. “He had this mixture of being firm yet compassionate.”