To the extent that we remember at all, Americans have only a dim idea how we got first got involved in Afghanistan. Something about the Soviet invasion, followed by the CIA and "Charlie Wilson's War." Husain Haqqani tells some more of the story in "Magnificent Delusions."
After Army Chief Zia-ul-Hac overthrew the elected government of Pakistan and murdered the elected President, he faced rebellions in some provinces. When the British divied up the subcontinent, they had deliberately divided the Pashtun peoples, placing some of them in Pakistan and the rest in Afghanistan. This resulted in persistent demands for a united "Pashtunistan." Meanwhile, a somewhat leftist government had been elected in Afghanistan and adopted policies (land reform, rights for women) that offended large landowners and Islamic fundamentalists.
Zia responded by training, funding, and supplying Islamist insurgents, creating an Afghan civil war. This war probably played a key role in provoking or enabling the rather small Communist faction into overthrowing the elected Afghan government and taking power. At this point, Zia, pointing to the Communist threat, was able to enlist American President Jimmy Carter into small scale support for Zia-ul-Hac's Afghanistan war - thereby making the US the first great power to become deeply involved. Six months later, the Soviets invaded.
Because Pakistan, against US wishes, was developing a nuclear weapon, the US had stopped all military aid to Pakistan. The Soviet invasion changed all that.
The US policy that emerged immediately after Soviet troops moved into Afghanistan revolved around Pakistan. As Vance wrote in his memoir, Carter was willing to seek congressional approval to waive the legal prohibition on military aid to Pakistan. At the same time the United States would reaffirm its nuclear nonproliferation policy and press Pakistan to provide acceptable guarantees that it would not develop a nuclear weapon. But the first step was to reach agreement with Pakistan on the terms of an assistance package.
The relationship between the United States and Pakistan had flipped. The New York Times headline “Pakistan Is No Longer the Ardent Suitor, but the Prize to Be Courted” captured it exactly. 56 Zia handled the new situation with panache. He was eager to partner with the United States, but he made it seem like a difficult decision. He emphasized Pakistan’s “strategic position” and its being the “backdoor to the Gulf” and praised the United States as the champions of the free world. 57 But he also spoke of the vulnerability of Pakistan to Soviet and Indian pressures.
Haqqani, Husain (2013-11-05). Magnificent Delusions: Pakistan, the United States, and an Epic History of Misunderstanding (pp. 247-248). PublicAffairs. Kindle Edition.
In effect, Zia had mouse trapped the US and the Soviets into a confrontation that ultimately would be disastrous to both.
Zia was both a cunning and treacherous fellow, but his plans could not have succeeded without a large dollop of American stupidity.
Here is Reagan, somewhat later:
After meeting Zia, Reagan wrote in his diary for that Tuesday: “The weather turned out fine for the official greeting ceremony for Pres. Zia of Pakistan. We got along fine. He’s a good man (cavalry). Gave me his word they were not building an atomic or nuclear bomb. He’s dedicated to helping the Afghans & stopping the Soviets.”
Haqqani, Husain (2013-11-05). Magnificent Delusions: Pakistan, the United States, and an Epic History of Misunderstanding (p. 229). PublicAffairs. Kindle Edition.