Mohammed Zahir Shah, Nadir Shah's 19-year-old son, succeeded to the throne and reigned from 1933 to 1973. Until 1946 Zahir Shah ruled with the assistance of his uncle, who held the post of Prime Minister and continued the policies of Nadir Shah. Another of Zahir Shah's uncles, Shah Mahmud Khan, became Prime Minister in 1946 and began an experiment allowing greater political freedom, but reversed the policy when it went further than he expected. In 1953, he was replaced by Mohammed Daoud Khan, the king's cousin and brother-in-law. Daoud sought a closer relationship with the Soviet Union and a more distant one towards Pakistan. Afghanistan remained neutral and was not a participant in World War II, nor aligned with either power bloc in the Cold War. However, it was a beneficiary of the latter rivalry as both the Soviet Union and the United States vied for influence by building Afghanistan's main highways, airports and other vital infrastructure. By the late 1960s many western travelers were using these as part of the hippie trail. In 1973, Zahir Shah's brother-in-law, Daoud Khan, launched a bloodless coup and became the first President of Afghanistan while Zahir Shah was on an official overseas visit. Daoud Khan tried to implement some much needed reforms especially in the economic sector.
In 1978, a prominent member of the People's Democratic Party of Afghanistan (PDPA), Mir Akbar Khyber, was allegedly killed by the Daoud government. Leaders of the PDPA feared that Daoud was planning to dismantle them because many were being arrested. Hafizullah Amin along with other PDPA members managed to remain at large and organised an uprising. The PDPA, led by Nur Mohammad Taraki, Babrak Karmal and Hafizullah Amin, overthrew the regime of Mohammad Daoud, who was assassinated along with his family during the April 1978 Saur Revolution. Taraki was declared President, Prime Minister and General Secretary of the PDPA. Once in power, the PDPA implemented a socialist agenda. It moved to carry out an ill-conceived land reform, which was misunderstood by virtually all Afghans. They also imprisoned, tortured or murdered thousands of members of the traditional elite, the religious establishment, and the intelligentsia. They also prohibited usury and made a number of statements on women's rights, by declaring equality of the sexes and introducing women to political life. Anahita Ratebzad was one of several female Marxist leaders and a member of the Revolutionary Council.
As part of its Cold War strategy, the White House in the United States began recruiting, financing and arming Mujahideen fighters during Operation Cyclone in 1979, which was aimed to defeat the Soviets. President Jimmy Carter's National Security Advisor, Zbigniew Brzezinski, warned at the time that this might prompt a Soviet intervention. In March 1979, Hafizullah Amin took over as prime minister, retaining the position of field marshal and becoming vice-president of the Supreme Defence Council. Taraki remained President and in control of the army until September 14 when he was killed.
To bolster the Parcham faction, the Soviet Union decided to intervene on December 24, 1979, when the Red Army invaded its southern neighbor. Over 100,000 Soviet troops took part in the invasion, which was backed by another one hundred thousand Afghan military men and supporters of the Parcham faction. In the meantime, Hafizullah Amin was killed and replaced by Babrak Karmal. In response to the Soviet occupation of Afghanistan, the Reagan administration in the U.S. increased arming and funding of the Mujahideen who began a guerilla war thanks in large part to the efforts of Charlie Wilson and CIA officer Gust Avrakotos. Early reports estimated that $6–20 billion had been spent by the U.S. and Saudi Arabia but more recent reports state that the U.S. and Saudi Arabia provided as much as up to $40 billion in cash and weapons, which included over two thousand FIM-92 Stinger surface-to-air missiles, for building up Islamic groups against the Soviet Union. The U.S. handled most of its support through Pakistan's ISI. Saudi Arabia was also providing financial support. Leaders such as Ahmad Shah Massoud received only minor aid compared to Hekmatyar and some of the other parties.
The 10-year Soviet occupation resulted in the killings of between 600,000 and two million Afghans, mostly civilians. About 6 million fled as Afghan refugees to Pakistan and Iran, and from there over 38,000 made it to the United States and many more to the European Union. Faced with mounting international pressure and great number of casualties on both sides, the Soviets withdrew in 1989. Their withdrawal from Afghanistan was seen as an ideological victory in America, which had backed some Mujahideen factions through three U.S. presidential administrations to counter Soviet influence in the vicinity of the oil-rich Persian Gulf. The USSR continued to support President Mohammad Najibullah until 1992.
After the fall of the communist Najibullah-regime in 1992, the Afghan political parties agreed on a peace and power-sharing agreement. Gulbuddin Hekmatyar received operational, financial and military support from Pakistan. Pakistan was keen to gear up for a breakthrough in Central Asia. Islamabad could not possibly expect the new Islamic government leaders to subordinate their own nationalist objectives in order to help Pakistan realize its regional ambitions. Had it not been for the ISI's logistic support and supply of a large number of rockets, Hekmatyar's forces would not have been able to target and destroy half of Kabul. In addition, Saudi Arabia and Iran - as competitors for regional hegemony - supported Afghan militias hostile towards each other. According to Human Rights Watch, Iran was assisting the Shia Hazara Hezb-i Wahdat forces of Abdul Ali Mazari, as Iran was attempting to maximize Wahdat's military power and influence. Saudi Arabia supported the Wahhabite Abdul Rasul Sayyaf and his Ittihad-i Islami faction. Conflict between the two militias soon escalated into a full-scale war.
Due to the sudden initiation of the war, working government departments, police units or a system of justice and accountability for the newly-created Islamic State of Afghanistan did not have time to form. Atrocities were committed by individuals of the different armed factions while Kabul descended into lawlessness and chaos as described in reports by Human Rights Watch and the Afghanistan Justice Project. Because of the chaos, some leaders increasingly had only nominal control over their commanders. For civilians there was little security from murder, rape and extortion. An estimated 25,000 people died during the most intense period of bombardment by Hekmatyar's Hezb-i Islami and the Junbish-i Milli forces of Abdul Rashid Dostum, who had created an alliance with Hekmatyar in 1994. Half a million people fled Afghanistan.
Southern Afghanistan was under the control of neither foreign-backed militias nor the government in Kabul, but was ruled by local leaders such as Gul Agha Sherzai and their militias. In 1994, the Taliban (a movement originating from Jamiat Ulema-e-Islam-run religious schools for Afghan refugees in Pakistan) also developed in Afghanistan as a politico-religious force, reportedly in opposition to the tyranny of the local governor. Mullah Omar started his movement with fewer than 50 armed madrassah students in his hometown of Kandahar. When the Taliban took control of the city in 1994, they forced the surrender of dozens of local Pashtun leaders who had presided over a situation of complete lawlessness and atrocities. In 1994, the Taliban took power in several provinces in southern and central Afghanistan.
In late 1994, most of the militia factions (Hezb-i Islami, Junbish-i Milli and Hezb-i Wahdat) which had been fighting in the battle for control of Kabul were defeated militarily by forces of the Islamic State's Secretary of Defense Ahmad Shah Massoud. Bombardment of the capital came to a halt. The Islamic State government took steps to restore law and order. Courts started to work again. Massoud tried to initiate a nationwide political process with the goal of national consolidation and democratic elections, also inviting the Taliban to join the process. The Taliban declined.The Taliban started shelling Kabul in early 1995 but were defeated by forces of the Islamic State government under Ahmad Shah Massoud. The Taliban's early victories in 1994 were followed by a series of defeats that resulted in heavy losses. Pakistan provided strong support to the Taliban. Many analysts like Amin Saikal describe the Taliban as developing into a proxy force for Pakistan's regional interests which the Taliban decline. On September 26, 1996, as the Taliban with military support by Pakistan and financial support by Saudi Arabia prepared for another major offensive, Massoud ordered a full retreat from Kabul. The Taliban seized Kabul on September 27, 1996, and established the Islamic Emirate of Afghanistan. They imposed on the parts of Afghanistan under their control their political and judicial interpretation of Islam issuing edicts forbidding women to work outside the home, attend school, or to leave their homes unless accompanied by a male relative.