Since feudal times the landholding system in Afghanistan had remained unchanged, with more than 75 percent of the land owned by big landlords who comprised only 3 percent of the rural population. In the mid-1960s, democratic revolutionary elements coalesced to form the People's Democratic Party (PDP). In 1973, the king was deposed, but the government that replaced him proved to be autocratic, corrupt, and unpopular. It in turn was forced out in 1978 after a massive demonstration in front of the presidential palace, and after the army intervened on the side of the demonstrators.
The military officers who took charge invited the PDP to form a new government under the leadership of Noor Mohammed Taraki, a poet and novelist. This is how a Marxist-led coalition of national democratic forces came into office. "It was a totally indigenous happening. Not even the CIA blamed the USSR for it," writes John Ryan, a retired professor at the University of Winnipeg, who was conducting an agricultural research project in Afghanistan at about that time.
The Taraki government proceeded to legalize labor unions, and set up a minimum wage, a progressive income tax, a literacy campaign, and programs that gave ordinary people greater access to health care, housing, and public sanitation. Fledgling peasant cooperatives were started and price reductions on some key foods were imposed...
Because of its egalitarian and collectivist economic policies the Taraki government also incurred the opposition of the US national security state. Almost immediately after the PDP coalition came to power, the CIA, assisted by Saudi and Pakistani military, launched a large scale intervention into Afghanistan on the side of the ousted feudal lords, reactionary tribal chieftains, mullahs, and opium traffickers.
A top official within the Taraki government was Hafizulla Amin, believed by many to have been recruited by the CIA during the several years he spent in the United States as a student. In September 1979, Amin seized state power in an armed coup. He executed Taraki, halted the reforms, and murdered, jailed, or exiled thousands of Taraki supporters as he moved toward establishing a fundamentalist Islamic state. But within two months, he was overthrown by PDP remnants including elements within the military.
It should be noted that all this happened before the Soviet military intervention. National security adviser Zbigniew Brzezinski publicly admitted--months before Soviet troops entered the country--that the Carter administration was providing huge sums to Muslim extremists to subvert the reformist government. Part of that effort involved brutal attacks by the CIA-backed mujahideen against schools and teachers in rural areas.
In late 1979, the seriously besieged PDP government asked Moscow to send a contingent of troops to help ward off the mujahideen (Islamic guerrilla fighters) and foreign mercenaries, all recruited, financed, and well-armed by the CIA. The Soviets already had been sending aid for projects in mining, education, agriculture, and public health. Deploying troops represented a commitment of a more serious and politically dangerous sort. It took repeated requests from Kabul before Moscow agreed to intervene militarily.
TL;DR: An organic, popular left-wing government deposed the king and made some serious reforms that challenged capital. Then -- and stop me if you've heard this one before -- capital interests and social reactionaries allied with the U.S. and its client states to attack said popular left-wing government. This pushed the left-wing government into the USSR's camp (again, stop me if this sounds familiar) and it asked the Soviet Union for more and more help, up to and including military assistance.
It wasn't quite that simple:
TL;DR: An organic, popular left-wing government deposed the king and made some serious reforms that challenged capital. Then -- and stop me if you've heard this one before -- capital interests and social reactionaries allied with the U.S. and its client states to attack said popular left-wing government. This pushed the left-wing government into the USSR's camp (again, stop me if this sounds familiar) and it asked the Soviet Union for more and more help, up to and including military assistance.