E.J. Graff, author of ‘What is Marriage For? The Strange Social History of Our Most Intimate Institution,’ is a senior fellow at the Schuster Institute for Investigative Journalism at Brandeis University.

W he n a federal judge in Kentucky sent county clerk Kim Davis to jail last month for refusing to issue marriage licenses to same-sex couples, many evangelicals and conservatives cheered Davis as a martyr for biblical truth, but most mainstream politicians and news outlets essentially rolled their eyes at her refusal to carry out the law.

And that makes my head spin.

Only 20 years ago, Americans overwhelmingly agreed with Davis that same-sex marriage was a ridiculous idea. Only 60 years ago, federal, state and local governments and the mainstream media enforced her beliefs, sending homosexuals to jail and shaming them publicly for their immoral perversions.

What the heck happened? How did a once-despised minority win full formal equality (with some caveats, below)? How did gay people become moral heroes to many Americans while Davis and her like became the ridiculed outcasts?

‘The Gay Revolution: The Story of the Struggle’ by Lillian Faderman (Simon & Schuster)

Lillian Faderman has the sprawling, complicated answer in “The Gay Revolution.” This is the history of the gay and lesbian movement that we’ve been waiting for: compulsively readable, carefully anchored in the historical record, overflowing with riveting stories, human peculiarities and thoughtful analysis of the messy political contradictions that dogged this untidy movement. Other books have purported to explain how the unruly LGBT movement triumphed. “The Gay Revolution” succeeds.

The book opens in 1948, as a respected and beloved journalism professor at the University of Missouri turns himself in to police. After the professor was outed in a witchhunt that involved coercing gay men to identify their sodomitic co-conspirators, a warrant was issued for his arrest. The professor tries to fight back — but it’s the wrong era. He is jailed, shamed and stripped of his reputation, career and pension. And he’s not alone: Faderman shows us one such persecution after another, illustrating the heartbreaking climate for every major national issue on which lesbian and gay people have since triumphed.

For those of us who’ve been reading gay history since scholars such as Faderman, George Chauncey, John D’Emilio and Michael Bronski began publishing their research several decades ago, some of what follows is as familiar as a bedtime story. In California, here’s groundbreaking gay activist Harry Hay getting ousted from Mattachine, the “homophile” group he started, after the middle-class men and women it attracted began to reject his communism and aim instead for respectability. In the District of Columbia, there’s Hay’s mirror image, Frank Kameny, a brilliant astronomer who in 1957 was dismissed from the U.S. Army Map Service and stripped of his federal security clearance for homosexuality — and who became a lifetime crusader for gay rights. Here’s Barbara Gittings in her proper dress and Kameny in his shirt and tie, the “mother” and “father” of the gay rights movement, politely picketing the federal government at a time when doing so could destroy lives. Here is the drag queens’ giddily angry kickline at the 1969 Stonewall Inn riots, as street youth and butch lesbians and outcast gay folk refuse, at long last, to be carted off to jail for being queer.

But even as Faderman builds on 40 years of scholarship in LGBT history, she goes beyond what’s already been chronicled, beyond the familiar peaks and valleys that have entered the culture’s civil rights lexicon. For every story I already knew — and many I did not — Faderman offers new material, insights, anecdotes or syntheses. She has delved into the collected papers and archival materials that have begun finding their way into scholarly libraries. She has done original interviews with such lesser-known but critical players as Col. Margarethe Cammermeyer, a pioneer in working to knock down the gay exclusion from military service before “don’t ask, don’t tell”; with Michael Petrelis, who along with furious prophet Larry Kramer helped found and build ACT UP into an outrageously effective organization that forced the U.S. government to respond to the AIDS epidemic; with New England legal powerhouse Mary Bonauto, whose painstaking strategy and tactics won the early victories that helped ignite the marriage movement — and the backlash — in the rest of the nation.

One of Faderman’s finds has to do with the campaign by lesbians and gay men to persuade the American Psychiatric Association to stop listing homosexuality as a mental illness. Key activists managed to get a booth and panel at the APA’s 1972 convention — possibly the first time many of the attendees would see a gay person who wasn’t coming in for treatment. They strategized to make the panel persuasive. Gittings and Kameny agreed to be on the panel, along with two non-gay psychiatrists who did not think that homosexuality was an illness. “Kay Tobin, Gitting’s partner, came up with a startling suggestion. ‘You’ve got two gays who are not psychiatrists and two psychiatrists who are not gay. What you need now is a gay psychiatrist.’ Gittings and Kameny understood good theater. . . . Giddings started searching for the fifth psychiatrist.”

Unfortunately, all the gay shrinks were afraid of losing their jobs and their standing. At last, Gittings tracked one down who was willing to consider joining the panel — but not as himself. So Gittings had an idea: disguise him. Kameny exploded in anger, saying that would go against everything they stood for, but he couldn’t find an alternative. The gay shrink was John Fryer, who “was six feet four, weighed about three hundred pounds, and had bulldog jowls. Disguise seemed impossible. But Fryer’s lover, a drama major in college, was tickled by the challenge. He dressed Fryer in a tuxedo that was three sizes too large and so made him look smaller, a rubber mask of Richard Nixon that went over his head and face and was crimped to look clown-like, and a frizzy fright wig. . . . He was billed as Dr. H. Anonymous. Kameny had to concede he’d been wrong about not presenting a psychiatrist in disguise. The effect was sensational. . . . [At the end of his talk, Fryer] was given a standing ovation.”

I also learned here how former California governor Ronald Reagan was persuaded to oppose the Briggs initiative, which would have made it illegal for any gay person to teach school, and in doing so prevented it from becoming law. And Faderman introduces then-closeted Midge Costanza, an aide to Jimmy Carter, who lost her position after she organized a White House meeting with gay activists led by her unacknowledged girlfriend — a story I’d heard only through gossip and which was certainly not this meticulously footnoted.

Through anecdotes like these, we watch as lesbians and gay men take political positions, win public office, build national organizations and achieve Supreme Court victories — interrupted by plague, assassination, sickening ballot campaigns, witchhunts and abhorrent federal laws, all outmatched by ever more organizing. It’s thrilling.

Part of what’s thrilling is how Faderman shows these activists and actions with flaws and all, portraying the chaos and infighting, the deep and angry divisions. She shows lesbians and gay men often fighting one another, sometimes about sexism, sometimes about which issues to emphasize (say, opposition to raids on men having sex in bathrooms, or fighting for women’s right to continue to see their children after divorcing their husbands and dating women). She covers the clashes between the radicals and elites, the ones who wanted to tear down the establishment and the ones who wanted to be the establishment. She shows the loony utopians — separatist collectives, anyone? — and the inside players. She shows the decades-long internal struggles over how to win: Should a campaign timidly talk about human rights and abstract principles, or openly argue in favor of gay people’s humanity and families. And if the latter, how?

Of course, the book is not complete. Even 600-plus pages of text couldn’t possibly chronicle every effort over almost 70 years. Faderman concentrates on national action, with some bias toward California and the West Coast. She leaves out myriad state organizing efforts, in which courageous individuals around the country painstakingly built local coalitions and trained their state leaders and legislators to see gay people as worthy of anti-discrimination protections. But if she can’t tell every story, she tells enough of the right ones to paint the big picture well.

The book ends with President Obama calling Edie Windsor from Air Force One to thank her for helping to bring down the Defense of Marriage Act in Windsor v. United States, the penultimate step in dismantling same-sex couples’ exclusion from U.S. marriage laws. Today, lesbians and gay men are full citizens of our republic. Which isn’t the same as full acceptance or cultural welcome. Many young people still have to come out in the hostile microclimates of their families or are bullied in school; LGBT people aren’t covered by any national anti-discrimination laws, an especially important shortcoming in those parts of the country where we’re still thought to be perverted and queer; skirmishes are continuing with our most determined religious opponents; bisexuals are still eyed with suspicion; and the transgender column is a couple of decades behind the other letters in winning acceptance and freedom. The story is far from over.

But there’s no denying that a couple of generations of gay men and lesbians — Faderman’s generation and mine — grew up being spat upon, bashed and threatened for being queer. Now, amazingly enough, we are more often than not treated as boring and normal. “The Gay Revolution” tells you who changed our world, and how.

The Story of the Struggle

By Lillian Faderman

Simon & Schuster. 794 pp. $35