Say the words “Secret Service,” and — thanks to countless television and Hollywood dramas — it’s a safe bet that nearly every American will instantly summon up the image of a clean-cut, watchful agent in a dark suit, murmuring discreetly into a small microphone. For most of us, the Secret Service is synonymous with sober professionalism and selfless courage. But in “Zero Fail: The Rise and Fall of the Secret Service,” Carol Leonnig offers a powerful antidote to Hollywood fantasies. There’s plenty of courage in the Secret Service as Leonnig describes it, but not as much professionalism as you might think, and not nearly enough sobriety.

The modern Secret Service was born out of failure: After the assassinations of three presidents — Abraham Lincoln, James Garfield and William McKinley — in less than four decades, Congress tasked the agency, initially created for the sole purpose of combating counterfeiting, with presidential protection. It remained small and focused mainly on providing presidents with bodyguard services until another failure: the 1963 assassination of a fourth president, John F. Kennedy. Only after Kennedy’s assassination, Leonnig notes, did the Secret Service grow “from three hundred agents and a $5 million budget to seven thousand agents, officers and other staff and a budget of over $2.2 billion.”

Its mission also expanded: “Instead of protecting one leader, the agency now shields his extended family, many of his deputies, and even his political opponents,” and it has moved far beyond simple bodyguard services to also focus on protecting its charges from an ever-expanding and evolving range of threats, including cyberattacks and terrorist strikes. But as the Secret Service’s budget and mission have grown, so too have its flaws: Somewhere along the way, Leonnig charges, the “elite, hardworking band of patriots” determined to protect future presidents from JFK’s fate morphed into “a frat boy culture of infighting, indulgence and obsolescence.”

Leonnig, a Washington Post journalist with three Pulitzers under her belt, is thorough and unsparing in her account. Page by page and detail by implacable detail, she walks us through a catalogue of Secret Service blunders: its failure to prevent a near-fatal assassination attempt on George Wallace during his 1972 presidential campaign that left the Alabama governor paralyzed from the waist down; its acquiescence in President Richard Nixon’s illegal wiretapping schemes; its inability to stop would-be assassin John Hinckley from walking within 15 feet of President Ronald Reagan and opening fire; its failure to keep interlopers and flying bullets out of the White House on multiple occasions during the Bush and Obama presidencies; and its near-disastrous lack of preparation on 9/11, leaving Vice President Dick Cheney stranded outside the emergency shelter beneath the White House as a hijacked plane entered Washington airspace. (Apparently, no one had thought to give the agents in the vice-presidential detail access to the shelter.)

On top of these lapses, in recent decades the agency has been plagued by scandal after scandal, most involving sex, alcohol, drugs, racism or some combination of all four. The Secret Service looked the other way as President Bill Clinton’s compulsive womanizing created security risks (as the agency did previously with Kennedy’s womanizing), and top agents were repeatedly embroiled in embarrassing affairs of their own. In 2002, for instance, U.S. News & World Report broke a story about “a trail of horrendous behavior the Secret Service had tolerated in its highest ranks”: A senior agent slept with a female informant who subsequently overdosed in his bathroom; another agent provided drugs to his 16-year-old sex partner; a third agent went shopping and accidentally “left behind a highly sensitive and detailed security plan for protecting Vice President Cheney at a snowboard store.”

In 2008, eight years after Black agents sued the agency for race discrimination, the discovery process — long delayed by Secret Service foot-dragging — turned up a trove of emails in which senior agency officials swapped racist jokes, along with multiple instances of high-level officials downloading and sharing pornographic images. In 2012, eight agents were forced out of the Secret Service after hiring prostitutes during a night of drunken debauchery in Cartagena, Colombia; later that year, another agent killed himself when an internal investigation revealed multiple security lapses, including unreported overseas trips and affairs with foreign nationals. In 2014 and 2015, agents made headlines for drunken driving, including an episode in which two senior agents smashed their car into a White House security barrier after an alcohol-soaked retirement party for a colleague.

“Zero Fail” isn’t an easy read: Weighing in at nearly 500 pages of text, its sheer exhaustiveness is at times exhausting, and Leonnig struggles to bring life to what can feel like an unending chronicle of failures and missteps. There are simply too many characters jostling for attention in a book that covers more than six decades, and even Leonnig’s skillful writing can’t quite overcome the numbing impact of so much detail. The author is also curiously reluctant to judge most of the characters in her narrative; her effort to humanize even the most badly behaved and incompetent agents has an oddly flattening effect, leaving readers with no clear villains to blame for the Secret Service’s failings and no clear heroes to admire, either.

In the end, readers are left to ponder a troubling question: No president has been assassinated since 1963, but is this because of the Secret Service’s “skills, people, training, or technology” — or is it sheer “dumb luck”?

“Zero Fail” is an important book, one that will ruffle feathers in need of ruffling and that will be useful to legislators, policymakers and historians alike. Leonnig’s careful documentation of decades of neglect and malfeasance buttresses her observation that the Secret Service has become more and more of “a paper tiger, weakened by arrogant, insular leadership, promotions based on loyalty rather than capability, years of slim budgets, and outdated technology.”

Maybe this shouldn’t surprise us. Despite its Hollywood-enhanced reputation for squeaky-clean professionalism, the Secret Service is just like every other organization made up of humans, which is to say that it’s a bit of mess: It’s sloppy, hostile to newcomers and new ideas, and even its most dedicated and hard-working agents are constantly playing catch-up in the face of ceaselessly evolving threats.

But, Leonnig reminds us, ordinary human messiness isn’t quite good enough when it comes to something as vital as presidential security. Presidents, and the voters who elect them, have the right to expect more than an old boys club that sometimes seems to prioritize protecting its own over protecting the president.

Zero Fail

The Rise and Fall of the Secret Service

By Carol Leonnig

Random House. 532 pp. $30