And yet the myth of the C.I.A. as an all-knowing, all-powerful spy agency persisted for years, not just in the minds of America’s enemies but in the imagination of many American television-watchers and moviegoers. Among those fooled, at least initially, were most modern presidents of the United States. The promise of a secret intelligence organization that could not only spy on America’s enemies but also influence events abroad, by sleight of hand and at relatively low cost, was just too alluring.

When presidents finally faced the reality that the agency was bumbling, they could be bitter. Reviewing the C.I.A.’s record after his two terms in office, Dwight Eisenhower told the director, Allen Dulles, “I have suffered an eight-year defeat on this.” He would “leave a legacy of ashes” for his successor. A fan of Ian Fleming’s spy stories, John F. Kennedy was shocked to be introduced to the man described by C.I.A. higher-ups as their James Bond — the fat, alcoholic, unstable William Harvey, who ran a botched attempt to eliminate Fidel Castro by hiring the Mafia. Ronald Reagan went along with the desire of his C.I.A. director, William Casey, to bring back the mythical glory days by “unleashing” the agency — and his presidency was badly undermined by the Iran-contra affair.

In Weiner’s telling, a president trying to use the C.I.A. resembles Charlie Brown trying to kick the football. The role of Lucy is played by scheming or inept directors. Dulles is particularly egregious, a lazy, vain con artist who watches baseball games on television while half-listening to top-secret briefings (he assesses written briefings by their weight). Casey mumbles and lies and may have been almost mad from a brain tumor by the end. Even the more honorable directors, like Richard Helms, can’t resist telling presidents what they want to hear. To fit the policy needs of the Nixon White House in 1969, Helms doctored a C.I.A. estimate of Soviet nuclear forces. In a draft of the report, analysts had doubted the Soviet will or capacity to launch a nuclear strike. Helms erased this crucial passage — and for years thereafter, until the end of the cold war, the C.I.A. overstated the rate at which the Soviets were modernizing their arsenal. The C.I.A.’s bogus intelligence on Iraq in 2002-3, based on the deceits of dubious sources like the one known as Curveball, was hardly unprecedented. To justify the Johnson administration’s desire for a pro-war Congressional resolution on Vietnam in 1964, the intelligence community manufactured evidence of a Communist attack on American destroyers in the Gulf of Tonkin.

Weiner, a reporter for The Times who has covered intelligence for many years, has a good eye for embarrassing detail. High-ranking officials, it appears, were often the last to know. When Iraq invaded Kuwait in August 1990, Robert M. Gates, who is now the secretary of defense but at the time was the first President Bush’s deputy national security adviser, was at a family picnic. A friend of his wife’s joined the picnic and asked him, “What are you doing here?” Gates asked, “What are you talking about?” “The invasion,” she said. “What invasion?” he asked. A year earlier, when the Berlin Wall fell, Milt Bearden, the leader of the C.I.A.’s Soviet division, was reduced to watching CNN and deflecting urgent calls from White House officials who wanted to know what the agency’s spies were saying. “It was hard to confess that there were no Soviet spies worth a damn — they all had been rounded up and killed, and no one at the C.I.A. knew why,” Weiner writes. (The American agents in Moscow had been betrayed by the C.I.A. mole Aldrich Ames.)

Weiner is not the first reporter to see that the C.I.A.’s golden era was an illusion. After the 1975 Church Committee hearings exposed the agency as “the gang that couldn’t shoot straight,” various authors began to deconstruct the myth of the C.I.A., most notably Thomas Powers in “The Man Who Kept the Secrets.” But by using tens of thousands of declassified documents and on-the-record recollections of dozens of chagrined spymasters, Weiner paints what may be the most disturbing picture yet of C.I.A. ineptitude. After following along Weiner’s march of folly, readers may wonder: Is an open democracy capable of building and sustaining an effective secret intelligence service? Maybe not. But with Islamic terrorists vowing to set off a nuclear device in an American city, there isn’t much choice but to keep on trying.