WASHINGTON  In the frantic last hours of Gen. Stanley A. McChrystal’s command in Afghanistan, when the world wondered what was racing through the general’s mind, he reached out to an unlikely corner of his life: the author of the book “Three Cups of Tea,” Greg Mortenson.

“Will move through this and if I’m not involved in the years ahead, will take tremendous comfort in knowing people like you are helping Afghans build a future,” General McChrystal wrote to Mr. Mortenson in an e-mail message, as he traveled from Kabul to Washington. The note landed in Mr. Mortenson’s inbox shortly after 1 a.m. Eastern time on June 23. Nine hours later, the general walked into the Oval Office to be fired by President Obama.

The e-mail message was in response to a note of support from Mr. Mortenson. It reflected his broad and deepening relationship with the United States military, whose leaders have increasingly turned to Mr. Mortenson, once a shaggy mountaineer, to help translate the theory of counterinsurgency into tribal realities on the ground.

In the past year, Mr. Mortenson and his Central Asia Institute, responsible for the construction of more than 130 schools in Afghanistan and Pakistan, mostly for girls, have set up some three dozen meetings between General McChrystal or his senior staff members and village elders across Afghanistan.