Rise of al-Qaeda
The Soviet invasion in 1979, and the 10 years of occupation that followed, provided a magnet for would-be jihadists from around the Arab world. Some 35,000 of them flocked to Afghanistan during that period, to join the jihad and help the mainly Islamist Afghan mujahideen guerrillas turn the country into Russia's Vietnam.
There is little evidence that the "Afghan Arabs", as they became known, played a pivotal combat role in driving the Soviets out. But they made a major contribution in setting up support networks in Pakistan, channelling funds from Saudi Arabia and other donors, and funding schools and militant training camps. It was a fantastic opportunity for networking and forging enduring relationships as well as tasting jihad first hand.
Ironically, they found themselves on the same team as the Americans. The CIA's Operation Cyclone channelled hundreds of millions of dollars through Pakistan to militant Afghan mujahedeen leaders such as Golbuddin Hekmatyar, who associated closely with the Arab jihadists.
It was in Afghanistan that virtually all the major figures in the new jihadist world cut their teeth. They helped shape events there in the aftermath of the Soviet withdrawal in 1989, a period that saw the emergence of al-Qaeda as a vehicle for a wider global jihad, and Afghanistan provided a base for it.
By the time the Taliban took over in 1996, they were virtually in partnership with Osama Bin Laden and his men, and it was from there that al-Qaeda launched its fateful 9/11 attack in 2001.
The formative Afghan experience provided both the combat-hardened salafist jihadist leaders and the strategists who were to play an instrumental role in the emergence of the IS of today.
Most significant was the Jordanian jihadist Abu Musab al-Zarqawi, who more than anybody else ended up being the direct parent of IS in almost every way.
A high-school dropout whose prison career began with a sentence for drug and sexual offences, Zarqawi found religion after being sent to classes at a mosque in the Jordanian capital, Amman. He arrived in Pakistan to join jihad in Afghanistan just in time to see the Soviets withdraw in 1989, but stayed on to work with jihadists.
After a stint back in Jordan where he received a 15-year jail sentence on terrorist charges but was later released in a general amnesty, Zarqawi finally met Bin Laden and Ayman al-Zawahiri in 1999. By all accounts the two al-Qaeda leaders did not take to him. They found him brash and headstrong, and they did not like the many tattoos from his previous life that he had not been able to erase.
But he was charismatic and dynamic, and although he did not join al-Qaeda, they eventually put him in charge of a training camp in Herat, western Afghanistan. It was here that he worked with an ideologue whose radical writings became the scriptures governing subsequent salafist blood-letting: Abu Abdullah al-Muhajir.
"The brutality of beheading is intended, even delightful to God and His Prophet," wrote Muhajir in his book The Theology of Jihad, more generally referred to as the Theology of Bloodshed. His writings provided religious cover for the most brutal excesses, and also for the killing of Shia as infidels, and their Sunni collaborators as apostates.
The other book that has been seen as the virtual manual - even the Mein Kampf - for IS and its forebears is The Management of Savagery, by Abu Bakr Naji, which appeared on the internet in 2004.
"We need to massacre and to do just as has been done to Banu Qurayza, so we must adopt a ruthless policy in which hostages are brutally and graphically murdered unless our demands are met," Naji wrote. He was referring to a Jewish tribe in seventh-century Arabia which reportedly met the same fate at the hands of early Muslims as the Yazidis of Sinjar did nearly 14 centuries later: the men were slaughtered, the women and children enslaved.
Naji's sanctioning of exemplary brutality was part of a much wider strategy to prepare the way for an Islamic caliphate. Based partly on the lessons of Afghanistan, his book is a detailed blueprint for provoking the West into interventions which would further rally the Muslims to jihad, leading to the ultimate collapse of the enemy.
The scenario is not so fanciful if you consider that the Soviet Union went to pieces barely two years after its withdrawal from Afghanistan.
Naji is reported to have been killed in a US drone strike in Pakistan's Waziristan province in 2008.