There is no greater historical example of an unstoppable force hitting an immovable object than the Soviet invasion and occupation of Afghanistan. Afghanistan is a mountainous, landlocked, harsh country that makes it very difficult for a great power to bring the full might of that power to bear against the locals. Naval forces are out and, in some area, so is air support. The harsh climate and vast nothingness and remotely populated areas makes supply lines difficult to establish and even harder to defend. But the Soviet Union opted to try anyway, invading in force in 1979.
Under Afghan King Mohammed Zahir Shah, the country was actually developing and modernizing fairly well... until his cousin Mohammed Daoud Khan overthrew him in 1973. He established an Afghan Republic and everything went to hell — for many reasons. Five years later, the Pashtun Nationalist government was overthrown in favor of a Communist regime and Afghanistan became a Cold War battlefront.
Communism did not sit well with the people in rural areas, who weren't used to the control (and taxes and land reforms) of a Communist central government. So, they started fighting back. Then-President Nur Mohammed Taraki asked the Soviet Union to help quell angry protests against a government that suddenly decided to execute so many of them for failing to comply with Communist reforms. That's when Hafizullah Amin, the Communist Prime Minister, killed Taraki and seized power.
Then, Soviet leader Leonid Brezhnev stepped in.
Seeing Afghanistan descending into chaos and worried that the Islamic Revolution in Iran might spread to Afghanistan and other traditionally muslim Soviet Socialist Republics, the USSR decided to move in — and pretty much failed from day one, which was Christmas Day, 1979.
At this point, the Soviets needed to do four things: legitimize the Communist central government in Kabul, rebuild the Afghan Army, destroy resistance to the new government, and win the hearts and minds of the common people they couldn't directly control.
People like this.
1. They could not establish the Communist government's legitimacy
Failure was immediate, beginning with the man at the top. After just months in power, Amin was out. Literally. One of the first governmental changes the Soviets made was to kill Amin and replace him with Babrak Kamal. This turned the image of the Soviet invasion from one of an intervention to stabilize the government to one of ownership over Afghanistan.
"Ownership" being the operative word.
2. They did not break the back of the resistance
While they were able to take the major cities, as well as transportation and communications centers, the Red Army quickly pushed tribal warlords into the mountainous regions, where they resolved to begin the Islamic Revolution that nobody had thought about until the Soviets invaded in the first place. Instead of conquering the country, they managed to unite Afghanistan's disparate population against them.
These guys, remember?
The one advantage the Red Army had over mujahideen fighters was their fleet of Hind helicopters. These allowed the Soviets to move people and equipment fast over long distances and into the high mountains. This silver lining lasted until the mid-1980s, when Stinger missiles began to appear in jihadi arsenals. With accurate anti-aircraft missiles, the mujahideen now had the ability to protect their mountainous hiding places and forced the Soviet Union to switch to a tactic of conducting nighttime raiding on enemy targets.
Soviet forces were concentrated in a mass along major highways in the country and in a series of fortified positions throughout their controlled areas. Outside of those areas, neither economy of forces nor consistent supply lines were ever established.
There's no Russian translation for "off the beaten path." Apparently.
In places like Khost, Soviet dominance was never even established. The Red Army established a helicopter base on the outskirts of the city, but the city itself spent 11 years under siege from the Mujahideen forces, cut off from the rest of Soviet operations. When a relief column came to the base in 1987, they reset the siege as soon as the Russians left.
The Soviet Union's previous experience with invading other countries was limited to East Germany, Hungary, and Czechoslovakia. Afghanistan and its people have little in common with the methods of fighting that work in Europe. The tactics employed by the Soviets were mostly of overwhelming firepower, including scorched-earth policies, carpet bombing, and the use of chemical weapons, none of which won them many friends among the people of the country they were trying to win over.
A map of areas controlled by insurgent groups in Afghanistan in 1985.
3. The Soviets did not win over the hearts and minds of Afghan people
A narrative quickly formed that atheist Communists and traditionally Orthodox Christian Russian invaders were on a mission against Islam. Those Afghan warlords that were pushed out of major urban centers and villages came down from the mountains as a united Islamic front, the mujahideen. With the Cold War in full swing, the United States decided to help fuel the fire by supplying the mujahideen with weapons and equipment to help their jihad against the USSR.
Fighters and money flowed into the mujahideen's ongoing guerrilla war against the Soviet Union from all corners of the Islamic world. Between 1980 and 1985, the Red Army stomped the mujahideen in a series of battles in the Panjshir Valley against the forces of rebel leaders like Ahmad Shah Massoud. But Massoud would always live to rebuild his forces and come back at the Russian bear.
The Soviets could win as many pitched battles as they wanted, kill as many Afghan fighters as possible, but the endless tide of money and men would mean that the battles would just be fought over and over. Search-and-destroy missions were not going to pacify Afghanistan. In fact, all it did was either kill the population or turned them into refugees — a full one-third of Afghanistan's population was killed or fled during the Soviet occupation.
Soviet ground forces in action while conducting an offensive operation against the Islamist resistance, the Mujahideen.
4. The Afghan Army was never an effective force
The Red Army brought in allied advisors from friendly countries to train the Afghan Army in warfighting methods more appropriate than the methods they actually used. Cuban troops who were familiar with insurgency operations from places like Angola and Ethiopia trained the burgeoning Afghan government troops, but the consistent lack of actual combat experience in these tactics wasted a lot of the time they could have spent creating a veteran fighting force.
Furthermore, the inefficient communications and logistics involved with large-scale Soviet operations did little to convince the nascent Afghan troops that their training methods and lessons had any real applicability in real-world fighting. When the Russians left and the Soviet Union fell, many of these trained fighters defected to the mujahideen, leading to the fall of the Afghan Communist regime.
"Set it up like this, it goes bang. Good work, comrade."
The Soviet Union would stay in Afghanistan until February 1989. They still supported the Communist Afghan government against the mujahideen, which continued until the USSR collapsed in on itself in 1991. In April 1992, mujahideen troops under Ahmad Shah Massoud captured Kabul. But the factional violence within the jihadists didn't stop and another civil war began.
This time, the victors were an upstart group of hardline Islamists, known as the Taliban.