In “The Wars of Afghanistan,” Peter Tomsen builds a compelling case for blaming much of the U.S. heartache in Afghanistan on its supposed ally in the region, Pakistan. Indeed, Tomsen’s book, which provides a sweeping look at Afghanistan and its legacy of turmoil, offers among its many policy prescriptions that the United States withhold military aid to its ally, because the more funds that go to Islamabad, the stronger the Taliban seems to become. I took it as a sign of Tomsen’s acuity that on the day I finished reading his book, the United States announced it would not release $800 million intended for Pakistan’s military support.

Tomsen was the U.S. special envoy to the Afghan resistance groups from 1989 to 1992, the years right after they drove out Soviet troops. He had close relationships with a range of major players — Afghan commanders, mullahs and politicians, Pakistani generals, Soviet diplomats and Saudi princes — and he pours his insights into this thick, important volume adding up to more than 700 pages of text.

The book begins with a brief look at Afghanistan’s history. Tomsen calls the country a “shatter zone” because it was repeatedly invaded by stronger powers and then it invariably defeated or outlasted its occupiers. The key to the nation’s resilience, he notes, is its reliance on thousands of isolated communities that were always willing to fight but never willing to give up their independence. This fragmented structure affected how Afghanistan was governed: The leadership in Kabul survived only by forging alliances with enough tribes and ethnic groups to achieve critical weight and maintain stability. Tomsen’s historical narrative helps us understand how Afghanistan in the 20th century was able to achieve not only intermittent calm and prosperity but also gradual democratization. Afghan progress was undermined in the 1970s, however, when a right-wing coup was followed by a left-wing takeover and the disastrous Soviet intervention.

Tomsen expresses his dismay at U.S. policy toward the triumphant Afghan factions that finally forced the Soviet withdrawal. The United States took a neutral stance toward the disparate Afghan resistance groups — a lack of attention at a critical time that Tomsen and other observers argue allowed for the rise of undesirable factions. Pakistan and Saudi Arabia favored the most fanatical Islamist groups to the detriment of religious moderates and nationalists.

It was at this time that for a full decade the United States “outsourced” its Afghan policy to Pakistan, Tomsen says. The country crumbled into civil war that ceased only after Pakistan formed, funded and supplied the rigidly Islamist Taliban, which calmed the fighting and spread Pakistan’s influence. But the deal backfired when the Taliban proved not so pliable and played host to al-Qaeda, which inspired the country’s latest invasion — by America. Pakistan promptly promised cooperation with the United States and its coalition but, Tomsen argues, Islamabad has been double-dealing the United States ever since its involvement in Afghanistan after 9/11. Pakistan had handled the Soviet incursion into its sphere of influence in similar fashion, Tomsen says, and now the United States is operating under a “Grand Delusion” in which policymakers refuse to recognize that their ally is both fireman and arsonist in its determination to maintain its strategic depth in the Afghan nation. Tomsen is clearly sympathetic to the Afghans and details their nuances intimately, while tending to generalize about Pakistan — I wished the book had more on that state’s own fragility and its geopolitical dilemmas.

‘The Wars of Afghanistan: Messianic Terrorism, Tribal Conflicts, and the Failures of Great Powers’ by Peter Tomsen. PublicAffairs. 849 pp. $39.99 (PublicAffairs)

“The Wars of Afghanistan” contains many compelling vignettes, which demonstrate the author’s proximity to the principals. Tomsen provides unprecedented detail in recounting the death of the resistance icon Ahmed Shah Massood two days before 9/11. His account of Massood reading poetry on the night before his assassination, which his companion found portentous, adds a poignant touch to the hero’s death. Tomsen was also in the same convoy as Hamid Karzai in 2002 when a Taliban assassin thrust an AK-47 through the Afghan leader’s car window but the weapon fortunately misfired.

This long-overdue work, which takes us up to the recent killing of Osama bin Laden, is the most authoritative account yet of Afghanistan’s wars over the past 30 years and should be essential reading for those wishing to forge a way forward without repeating the mistakes of the past.

Stephen Tanner is author of “Afghanistan: A Military History, from Alexander the Great to the War Against the Taliban.”