It wasn’t until around 2004 that Flanigan found an answer, one that was given legitimacy by the American Psychological Association (A.P.A.) five years later and one that complicated the conventional wisdom about sexual identity and sexual orientation. Is it possible, he wondered, that the most psychologically sound alternative for truly devout gay men and women would be to defy both groups? It is an approach that Flanigan is sure has relieved suffering among his deeply conflicted clients, and yet he sometimes is struck by the method he has chosen. As he explained it to me, “The idea that I am helping the client stay in the closet is bizarre to me.”

The closet now seems a vestige of a much darker era. Eve Kosofsky Sedgwick, the godmother of the academic field known as queer theory who wrote “Epistemology of the Closet,” called its hidden world “the defining structure for gay oppression in this century.” The world in which men wore red neckties to signal their homosexuality to each other or taught themselves to speak and walk more “manfully” or risked arrest and, in turn, social and financial ruin just to be with people like themselves, now seems as archaic as segregated water fountains. And as insidious: Alan Frank, a 71-year-old analyst in Manhattan, sought professional help in the 1960s when he was an ad-agency art director. He was married with a child and realized he was gay. Three times a week he went to a psychiatrist “whose job was to make me straight,” Frank told me. “I wanted that, because I thought being gay was deviant. I was a husband and a father, and I didn’t want to destroy that.” The psychiatrist took Frank into his backyard and taught him how to throw a baseball, asserting that it would make him “more manly and a better father.” He vomited during every session from the humiliation. “There’s hardly a gay man of my age who didn’t go through some form of aversion therapy,” he said. “This was an awful, awful thing that he did.” But at the time, Frank’s choices, and even his doctor’s choices, were few.

So Frank lived his life in secret, until he couldn’t stand it anymore. “I left my wife and I left that analyst, because I realized if I continued I would commit suicide,” he said. Times changed: more gays were coming out, especially in New York City, particularly after the American Psychiatric Association removed homosexuality from its manual of mental disorders in 1973. “I think when that stigma was taken away and we could be our authentic selves, that made an enormous difference.” He fell in love with an openly gay rabbi, and the two men lived together for 16 years until his partner’s death. Frank is now married to another man. In his practice, he specializes in gender and sexuality conflicts, helping men and women to free themselves from the shame surrounding sexual issues. “The closet was necessary,” Frank said. “It’s not necessary now.”

Frank came out while living in New York City. Flanigan says it’s harder where he lives. Despite the undeniable progress — gay marriage in five states; the repeal of “don’t ask, don’t tell”; mainstream icons like Ellen DeGeneres — “it’s not all O.K.,” Flanigan says. There is still discrimination, still bullying of gay kids. “In many states you can still be fired for being gay,” he says. And an even deeper fear exists for a small but hidden group, those whose faith condemns their orientation. As Judith Glassgold, who was the chairwoman of the A.P.A.’s Task Force on Appropriate Therapeutic Responses to Sexual Orientation, told me: “Back in the ’60s and ’70s, the people who sought treatment were the ones who struggled with the discrimination and prejudice that they faced, and sensed that they couldn’t have a life. But more recently, the people who come to treatment are people who have strong religious beliefs who cannot integrate that identity into their lives.”

Flanigan’s parents were Lutheran, but religion was never an important part of his life. “I rejected the church long before I was gay,” he told me. “But I still see the value of it in other people’s lives.” Still, coming out in high school in 1986 in Frederick, Md., was wrenching: “I thought my life was over,” Flanigan said. “My thoughts of a family and happiness were ruined.” So, too, he believed, was his dream of becoming a doctor. (“They won’t let a gay person become a pediatrician,” he told himself.) But in the months that followed, he drew on support from his parents, friends, teachers and an understanding therapist. In 1988, while a student at the University of Maryland, he became president of the gay student union. “I got over the delusion that I wouldn’t be able to have a professional life,” he said.