I am conducting thesis research on this topic.
The People's Democratic Party of Afghanistan (PDPA) came to power in April 1978 in what was later referred to as the "Saur Revolution" or "April Revolution." The reason for the timing of the coup was the assassination of Mir Akbar Khayber, a prominent PDPA official. Riots resulted from his funeral and the coup quickly followed.
Contrary to popular belief, the Soviet Union DID NOT desire a Communist government in Afghanistan at all, and even urged Nur Mohammad Taraki (the leader of the PDPA) not to go forward with the revolution, thinking it would be crushed. The KGB residency in Kabul was only informed of the impending revolution two days before it was scheduled to take place, indicating that the Soviets knew nothing about the coup. Primary sources provided by the Cold War History Project Digital Archives indicate that the Soviet Politburo was taken by total surprise.
In regards to how the communists came to power, it was rather similar to the Russian Revolution in 1917. The coup was not a widespread, popular anti-government movement, but rather was the action of a small segment of the Afghan army which walked into Kabul essentially unopposed, much like the communists in the Russian Revolution (there being relatively little to negligible bloodshed in both instances and the communist revolutionary forces actually being quite few in number). Captain Aslam Watanjar mobilized the Fourth Armored Brigade at Pul-i-Charki and advanced on Kabul with 50 tanks. Simultaneously, Colonel Abdul Qader led a mutiny at Bagram Airbase which enabled planes to bomb the Presidential Palace. The coup ended almost before it started, with President Daoud's government giving way to the communists. The fact that his governemnt crumbled when threatened by merely fifty tanks and some planes is telling of the regime's weakness at the time. However, this was by no means a popular movement, and the serious backlash to socialist reforms due to their conflicts with Islam over the next eleven years proves this.
The Soviet Union was then forced to both recognize and support the new PDPA government... if it failed, it would be a serious blow to Soviet and socialist prestige within the context of the Cold War. Although the Soviets did not desire a communist government, they were determined to keep it. One of the more notorious quotes by the Soviet leadership was said by KGB Chairman Yuri Andropov on 17 March 1979: "Bearing in mind that we will be labeled as an aggressor, but in spite of that, under no circumstances can we lose Afghanistan." On 25-27 December 1979, The Soviet Union invaded Afghanistan in order to depose Hafizullah Amin, who had murdered Taraki in an intraparty coup in September, and consolidate the communist regime in Afghanistan. In my estimation, the Soviets then pursued a genocidal policy of scorched earth tactics in order to isolate Mujahedeen fighters from the broader Afghan population {Chris Riehl, "The Soviet Occupation of Afghanistan: A Genocidal Perspective," Michigan Journal of History, Vol. 13, (Winter 2016): 277-305. https://michiganjournalhistory.files.wordpress.com/2015/09/mich-jour-hist-v13-draft-2017-jc-1.pdf}
Shameless plug: My research consists of analyzing Soviet foreign policy during the Brezhnev era by comparing the Soviet invasion of Czechoslovakia in 1968 to the invasion of Afghanistan in 1979. I emphasize the role of the KGB, Soviet military, and regional leaders in pushing the Politburo towards intervention... it should be published by December of this year!
tldr: The Afghan communist party (PDPA) took power with only a few military contingents and was NOT backed by popular Afghan support. The subsequent violent resistance to socialist reforms due to their "anti-Muslim" nature is evidence of this. The Communists struck at the right time while President Daoud's government was weak, and then immediately turned to the USSR to recognition and aid. The USSR categorically did NOT have a hand in the 1978 Revolution, contrary to popular belief.