Major Geoffrey Douglas Langlands was posted to the Indian army during World War II.

A former British officer who arrived in Pakistan with the Raj and stayed to become one of its most famous educators, with students including Prime Minister Imran Khan, has died in Lahore aged 101, officials said Wednesday.

Major Geoffrey Douglas Langlands was posted to the Indian army during World War II. After independence in 1947 he volunteered to stay on a while longer to help train the new Pakistani military.

But his brief posting turned into more than seven decades in Pakistan, during which he left the army to become one of the country's most revered teachers.

He was briefly kidnapped in the tribal areas, spent decades building a school in the mountainous northwest, and for years taught future Pakistani presidents and prime ministers including Khan at the prestigious Aitchison College -- known as the Eton of Pakistan -- in Lahore.

Profiled repeatedly in the British press, which documented among other things his daily breakfast of porridge, a poached egg and two cups of Lipton's tea, he finally retired in northwestern Chitral in 2012 at the age of 94.

"Aitchison College mourns the passing of Major Geoffrey Douglas Langlands, who left us quietly on Wednesday after a brief illness," the institution announced on its official website.

"Born on October 21, 1917 and affectionately known to all as 'The Major', we acknowledge the life of a soldier, teacher, gentleman, story-teller, mountaineer and humanitarian whose life was devoted in service to others and especially his adopted country Pakistan," the college said.

Langlands, who in his lifetime was awarded two of Pakistan's highest civilian awards, told Britain's Telegraph newspaper in 2012 of his experience being kidnapped while working as the principal of a cadet college in the Waziristan tribal district near the Afghan border.

He said the terrorists made him walk for hours through the mountains in winter to their village.

"The military could not assault the village because we would have been killed, so they got a party of elders to approach the kidnappers. They said, 'Look, you can't kidnap the principal.' So they agreed to release me," he said.

News of his death caused an outpouring on Pakistani social media.

Khan -- who, Langlands told the Guardian newspaper in 2009, "owes me quite a lot" -- tweeted an old class photo from Aitchison when he was 12 years old.

"Saddened to learn of the passing of my teacher. Apart from being our teacher, he instilled the love for trekking and our northern areas in me," he wrote.

"Pakistan has lost a great friend and a teacher of generations of its students," tweeted British High Commissioner Thomas Drew.