The Military history of Afghanistan () began before 1709 when the Hotaki dynasty was established in Kandahar followed by the Durrani Empire. The Afghan military was re-organized with assistance from the British in 1880, when the country was ruled by Amir Abdur Rahman Khan. It was modernized during King Amanullah Khan's rule in the early 20th century, and then during King Zahir Shah's forty-year rule; the Soviet Union supplied almost all weapons, training and military needs between the 1950s and 1970s. From 1978 to 1992, the Soviet-backed Afghan Armed Forces engaged in heavy fighting with the multi-national mujahideen groups who were then backed by the United States, Pakistan and others. After President Najibullah's resignation in 1992 and the end of Soviet support, the Afghan military dissolved into portions controlled by different factions. This era was followed by the Taliban regime, whose leaders were trained and influenced by the Pakistan Armed Forces.

After the removal of the Taliban regime in late 2001 and the formation of the Afghan Interim Administration, new military units were created. They were trained by NATO-member states, primarily by the United States. The Afghan Armed Forces operated independently but received some air support from the U.S. Air Force. As a major non-NATO ally, Afghanistan continued to receive billions of dollars in military assistance from the United States up until mid-2021.

With the Taliban takeover of Afghanistan in August 2021, the Islamic Republic Armed Forces were effectively dissolved, with the former insurgents becoming the country's new military. Remnants of the disbanded Afghan National Army regrouped to form the National Resistance Front of Afghanistan to wage guerrilla warfare against the Emirate.

Origins

Afghans have served in the militaries of the Ghaznavids (963–1187), Ghurids (1148–1215), Delhi Sultanate (1206–1527), Mughals (1526–1858) and the Persian army. The current Afghan military traces its origin to the early 18th century when the Hotaki dynasty rose to power in Kandahar and defeated the Persian Safavid Empire at the Battle of Gulnabad in 1722.

When Ahmad Shah Durrani formed the Durrani Empire in 1747, his Afghan army fought a number of wars in the Punjab region of Hindustan during the 18th to the 19th century. One of the famous battles was the 1761 Battle of Panipat in which the Afghans invaded and won a victory against the Maratha Empire. The Afghans then engaged multiple wars with the Sikh Empire. The Afghan–Sikh Wars saw major territorial losses for the Afghans. During the First Anglo-Afghan War, British India invaded Afghanistan in 1838 but withdrew in 1842. During these three years a number of battles took place in different parts of Afghanistan.

Traditionally, Afghan governments relied on three military institutions: the regular army, tribal levies, and community militias. The regular army was sustained by the state and commanded by government leaders. The tribal or regional levies - irregular forces - consisted of part-time soldiers provided by tribal or regional chieftains. The chiefs received tax breaks, land ownership, cash payments, or other privileges in return. The community militia included all available able-bodied members of the community, mobilized to fight, probably only in exceptional circumstances, for common causes under community leaders. Combining these three institutions created a formidable force whose components supplemented each other's strengths and minimized their weaknesses.

At the outbreak of the Second Anglo-Afghan War (1878–80) the regular army was about 50,000 strong and consisted of 62 infantry and 16 cavalry regiments, with 324 guns mostly organized in horse and mountain artillery batteries. Jalali writes that '..although Amir Shir Ali Khan (1863–78) is widely credited for founding the modern Afghan Army, it was only under Abdur Rahman that it became a viable and effective institution.' The Library of Congress Country Study for Afghanistan states:

Abdur Rahman was the creator of the modern Afghan state. When he came to the throne [in 1880], the army was virtually nonexistent. With the assistance of a liberal financial loan from the British, plus their aid in the form of weapons, ammunition, and other military supplies, he began a 20-year task of creating a respectable regular force by instituting measures that formed the long-term basis of the military system. These included increasing the equalization of military obligation by setting up a system known as the hasht nafari (whereby one man in every eight between the ages of 20 and 40 took his turn at military service); constructing an arsenal in Kabul to reduce dependence on foreign sources for small arms and other ordnance; introducing supervised training courses; organizing troops into divisions, brigades, and regiments, including battalions of artillery; developing pay schedules; and introducing an elementary (and harsh) disciplinary system.

20th century After the Third Anglo-Afghan War ended, the reforming Amanullah Khan did not see the need for a large army, instead deciding to rely on Afghanistan's historical martial qualities. This resulted in neglect, cutbacks, recruitment problems, and finally an army unable to quell the 1929 uprising that cost him his throne. However, under his reign, the Afghan Air Force was formed in 1924. The Afghan Armed Forces were expanded during King Zahir Shah's reign, reaching a strength of 70,000 in 1933. Adamec writes that the army was 60,000 strong in 1936, and included two corps in Kabul; three divisions in the Southern Province; one division Household troops (Guard Division); one artillery division; and two independent mixed divisions. Total divisions were 13 plus the artillery division. It is not clear how much the Army was involved in the Afghan tribal revolts of 1944–1947.

Soviet aid Following the Second World War, Afghanistan briefly received continued military support from the British government under the Lancaster Plan from 1945 to 1947, until the partition of India transformed British priorities. Afghanistan declined to join the 1955 United States-sponsored Baghdad Pact; this rebuff did not stop the United States from continuing its low-level aid program, but it was reluctant to provide Afghanistan with military assistance, so Daoud turned to the Soviet Union and its allies, and in 1955 he received approximately US$25 million of military aid.

During the 1950s and 1960s, Afghanistan purchased moderate quantities of Soviet weapons. It was mainly Sukhoi Su-7, Mikoyan-Gurevich MiG-21 fighter jets, T-34 and Iosif Stalin tanks, SU-76 self-propelled guns, GAZ-69 4x4 light trucks of jeep class (in many versions), ZIL-157 military trucks, Katyusha multiple rocket launchers, and BTR-40 and BTR-152 armored personnel carriers. Also included were PPSh-41 and RPK machine guns.

In addition, the Soviet Union and its allies began construction of military airfields in Bagram, Mazar-e-Sharif, and Shindand. By the 1960s, Soviet assistance started to improve the structure, armament, training, and command and control arrangements for the military. The Afghan Armed Forces reached a strength of 98,000 (90,000 soldiers and 8,000 airmen) by this period.

During this time in September 1960, irregulars & regulars of the Royal Afghan Army invaded the Bajaur district of Pakistan which resulted in intense skirmishes with Pakistani forces & local Pakistani tribesmen. However, the Afghan forces faced a defeat after they were flushed out of the area.

After the exile of King Zahir Shah in 1973, President Daud Khan forged stronger ties with the Soviets by signing two highly controversial military aid packages for his nation in 1973 and 1975. Between 1973 and 1978, Afghanistan obtained more sophisticated Soviet weapons such as Mi-4 and Mi-8 helicopters, Sukhoi Su-22 and Il-28 jets. A great many T-55, T-62, and PT-76 tanks arrived and huge amounts of AKM assault rifles were ordered. Armored vehicles delivered in the 1970s also included ZIL-135s, BMP-1s, BRDM-1s, BTR-60s, UAZ-469, and GAZ-66 as well as large quantities of small arms and artillery. The Afghan Armed Forces and police continued to receive up-to-date Soviet weapons, as well as training by the KGB and Soviet Armed Forces, for another three years. Due to problems with local political parties in his country, President Daud Khan decided to distance himself from the Soviets in 1976. He made Afghanistan's ties closer to the Greater Middle East and the United States instead.

By the time Daoud visited the Soviet Union again in April 1977, the Soviets were aware of his purge of the left that began in 1975, his removal of Soviet advisers from some Afghan military units, and his diversification of Afghan military training (especially to nations like India and Egypt, where they could be trained with Soviet weapons but not by Soviets).

In April 1978 there was a coup, known as the Saur Revolution, orchestrated by members of the government loyal to the People's Democratic Party of Afghanistan (PDPA). This led to a full-scale Soviet invasion in December 1979, led by the 40th Army and the Airborne Forces. In 1981 the total strength of the Afghan Armed Forces was around 85,000 troops according to The New York Times. The Afghan Army had around 35–40,000 soldiers, mostly conscripts; the Air Force had around 7,000 personnel; and the total of all military personnel was around 87,000 in 1984. Throughout the 1980s, the Afghan Armed Forces was heavily involved in fighting against the multi-national mujahiddin rebel groups who were largely backed by the United States and trained by the Pakistan Armed Forces. The rebel groups were fighting to force the Soviet Union to withdraw from Afghanistan as well as to remove the Soviet-backed government of President Mohammad Najibullah. Due to large number of defectors, the Afghan Armed Forces in 1985 were reduced to no more than about 47,000, the actual figure probably being lower. The Air Force had over 150 combat aircraft with about 7,000 officers who were supported by up to 5,000 Cuban Revolutionary Air and Air Defense Force and Czechoslovak Air Force advisers.

Under the Democratic Republic of Afghanistan (1978–1992), weapon deliveries by the Soviets were increased and included Mi-24 helicopters, MiG-23 fighter aircraft, ZSU-23-4 "Shilka" and ZSU-57-2 anti-aircraft self-propelled mounts, MT-LB armored personnel carriers, BM-27 "Uragan" and BM-21 "Grad" multiple-launch rocket systems and FROG-7 and Scud launchers. Some of the weapons that were not damaged during the decades of wars are still being used today.

Weapons supplies were made available to the mujahideen rebel groups through numerous countries; the United States purchased all of Israel's captured Soviet weapons clandestinely, and then funnelled the weapons to the mujahideen rebels, while Egypt upgraded their own Army's weapons, and sent the older weapons to the mujahideen, Turkey sold its World War II stockpiles to the warlords, and the British and Swiss provided Blowpipe missiles and Oerlikon anti-aircraft guns respectively, after they were found to be poor models for their own forces.Kinsella, Warren. "Unholy Alliances", Lester Publishing, 1992 China provided the most relevant weapons, likely due to their own experience with guerrilla warfare, and kept meticulous record of all the shipments.