In 1979 Soviet Union has been preparing for a military intervention in Afghanistan. The goal was changing the political leadership in Kabul. An odd 20 years later the similar task laid ahead of United States of America. Both superpowers were confident, that their mission will be finished fast and without any major difficulties. But both powers' plans were ruined by insurgents, which successfully countered the bigger and better equiped state armies. The intervention in Afghanistan was one of the main catalysts for the collapse of Soviet Union while twenty years later the Afghansitan war was the longest war in the history of United States of America. This thesis is exploring, how did both superpowers counter the insurgent threat in Afghanistan and why did both have so much trouble fighting the insurgents. Part of the thesis is focusing on military intervention, while the majority of the work is focused on the core of counterinsurgency: cooperation with the local civilian population and building the legitimacy of the government.