When the Supreme Court declared a constitutional right to same-sex marriage nearly eight years ago, social conservatives were set adrift.

The ruling stripped them of an issue they had used to galvanize rank-and-file supporters and big donors. And it left them searching for a cause that — like opposing gay marriage — would rally the base and raise the movement’s profile on the national stage.

“We knew we needed to find an issue that the candidates were comfortable talking about,” said Terry Schilling, the president of American Principles Project, a social conservative advocacy group. “And we threw everything at the wall.”

What has stuck, somewhat unexpectedly, is the issue of transgender identity, particularly among young people. Today, the effort to restrict transgender rights has supplanted same-sex marriage as an animating issue for social conservatives at a pace that has stunned political leaders across the spectrum. It has reinvigorated a network of conservative groups, increased fund-raising and set the agenda in school boards and state legislatures.

The campaign has been both organic and deliberate, and has even gained speed since Donald J. Trump, an ideological ally, left the White House. Since then, at least 20 states, all controlled by Republicans, have enacted laws that reach well beyond the initial debates over access to bathrooms and into medical treatments, participation in sports and policies on discussing gender in schools.

About 1.3 million adults and 300,000 children in the United States identify as transgender. These efforts have thrust them, at a moment of increased visibility and vulnerability, into the center of the nation’s latest battle over cultural issues.

“It’s a strange world to live in,” said Ari Drennen, the L.G.B.T.Q. program director for Media Matters, a liberal media monitoring group that tracks the legislation. As a transgender woman, she said, she feels unwelcome in whole swaths of the country where states have attacked her right “just to exist in public.”

The effort started with a smattering of Republican lawmakers advancing legislation focused on transgender girls’ participation in school sports. And it was accelerated by a few influential Republican governors who seized on the issue early.

But it was also the result of careful planning by national conservative organizations to harness the emotion around gender politics. With gender norms shifting and a sharp rise in the number of young people identifying as transgender, conservative groups spotted an opening in a debate that was gaining attention.

“It’s a sense of urgency,” said Matt Sharp, the senior counsel with the Alliance Defending Freedom, an organization that has provided strategic and legal counsel to state lawmakers as they push through legislation on transgender rights. The issue, he argued, is “what can we do to protect the children?”

Mr. Schilling said the issue had driven in thousands of new donors to the American Principles Project, most of them making small contributions.

The appeal played on the same resentments and cultural schisms that have animated Mr. Trump’s political movement: invocations against so-called “wokeness,” skepticism about science, parental discontent with public schools after the Covid-19 pandemic shutdowns and anti-elitism.

Nadine Smith, the executive director of Equality Florida, a group that fights discrimination against L.G.B.T.Q. people, said there was a direct line from the right’s focus on transgender children to other issues it has seized on in the name of “parents’ rights” — such as banning books and curriculums that teach about racism.

“In many ways, the trans sports ban was the test balloon in terms of how they can frame these things,” she said. “Once they opened that parents’ rights frame, they began to use it everywhere.”

For now, the legislation has advanced almost exclusively in Republican-controlled states: Those same policies have drawn strong opposition from Democrats who have applauded the increased visibility of transgender people — in government, corporations and Hollywood — and policies protecting transgender youths.

The 2024 presidential election appears poised to provide a national test of the reach of this issue. The two leading Republican presidential contenders, Mr. Trump and Gov. Ron DeSantis of Florida, who has not officially declared a bid, have aggressively supported measures curtailing transgender rights.

It may prove easier for Republicans like Mr. Trump and Mr. DeSantis to talk about transgender issues than about abortion, an issue that has been a mainstay of the conservative movement. The Supreme Court decision overturning the constitutional right to abortion created a backlash among Democrats and independents that has left many Republicans unsure of how — or whether — to address the issue.

Polling suggests that the public is less likely to support transgender rights than same-sex marriage and abortion rights. In a poll conducted in 2022, the Public Policy Research Institute, a nonpartisan research group, found that 68 percent of respondents favored allowing same-sex couples to marry, including 49 percent of Republicans.

By contrast, a poll by the Pew Research Center found that 58 percent of Americans supported requiring that transgender athletes compete on teams that match the sex they were assigned at birth; 85 percent of Republicans held that view.

“For many religious and political conservatives, the same-sex marriage issue has been largely decided — and for the American public, absolutely,” said Kelsy Burke, an associate professor of sociology at the University of Nebraska—Lincoln. “That’s not true when it comes to these transgender issues. Americans are much more divided, and this is an issue that can gain a lot more traction.”

The focus on perceived threats to impressionable children has a long history in American sexual politics. It has its roots in the “Save Our Children” campaign championed in 1977 by Anita Bryant, the singer known for her orange juice commercials, to repeal a local ordinance in Dade-Miami County that prohibited discrimination based on sexual orientation, a historic setback for the modern gay rights movements.

The initial efforts by the conservative movement to deploy transgender issues did not go well. In 2016, North Carolina legislators voted to bar transgender people from using the bathroom of their preference. It created a backlash so harsh — from corporations, sports teams and even Bruce Springsteen — that lawmakers eventually rescinded the bill.

As a result, conservatives went looking for a new approach to the issue. Mr. Schilling’s organization, for instance, conducted polling to determine whether curbing transgender rights had resonance with voters — and, if they did, the best way for candidates to talk about it. In 2019, the group’s research found that voters were significantly more likely to support a Republican candidate who favored a ban on transgender girls participating in school sports — particularly when framed as a question of whether “to allow men and boys to compete against women and girls” — than a candidate pushing for a ban on transgender people using a bathroom of their choosing.

With that evidence in hand, and transgender athletes gaining attention, particularly in right-wing media, conservatives decided to focus on two main fronts: legislation that addressed participation in sports and laws curtailing the access of minors to medical transition treatments.

In March 2020, Idaho became the first state to bar transgender girls from participating in girls’ and women’s sports, with a bill supporters in the Republican-controlled legislature called the “Fairness in Women’s Sports Act.”

A burst of state legislation began the next year after Democrats took control of Congress and the White House, ending four years in which social conservatives successfully pushed the Trump administration to enact restrictions through executive orders.

In the spring of 2021, the Republican-controlled legislature in Arkansas overrode a veto by Gov. Asa Hutchinson, a Republican, to enact legislation that made it illegal for minors to receive transition medication or surgery.

It was the first such ban in the country — and it was quickly embraced by national groups and circulated to lawmakers in other statehouses as a road map for their own legislation. The effort capitalized on an existing disagreement in the medical profession over when to offer medical transition care to minors. Despite that debate, leading medical groups in the United States, including the American Academy of Pediatrics, say the care should be available to minors and oppose legislative bans.

Later that spring, Mr. DeSantis, the Florida governor, traveled to a private Christian school in Jacksonville to sign a bill barring transgender girls from playing K-12 sports. With his approval, Florida became the largest state to date to enact such restrictions, and Mr. DeSantis signaled how important this issue was to his political aspirations.

“In Florida, girls are going to play girls’ sports and boys are going to play boys’ sports,” he said, winning applause from conservatives he would need to defeat Mr. Trump.

To some extent, this surge of legislation was spontaneous. Ms. Drennen, of Media Matters, said state lawmakers appeared to be acting out of a “general animus” toward transgender people, as well as a fear of political reprisals. “They are worried about this coming up in a primary,” she said.

But for several years, conservative Christian legal groups like the Alliance Defending Freedom and the Liberty Counsel have been shifting their resources.

In 2018, Kristen Waggoner, then the general counsel of the Alliance Defending Freedom, was the lead counsel in the Supreme Court defending a Colorado baker who, citing religious beliefs, refused to make a wedding cake for a same-sex couple. The court ruled narrowly in favor of the baker.

The next year, the Alliance took on a case involving a group of high school girls in Connecticut who challenged the state and five school boards for permitting transgender students to participate in women’s sports. Their lawsuit was rejected by a federal appeals court.

Mathew D. Staver, the founder and chairman of the Liberty Counsel, which was a major force behind a 2008 voter initiative in California that banned same-sex marriage, said the group is now fighting gender policies in the courts. It has challenged laws, often enacted in states controlled by Democrats, that restrict counseling services designed to change a person’s gender identity or sexual orientation, often referred to as conversion therapy.

“Those counseling bans violate first-amendment speech, because they only allow one point of view on the subject of sexuality,” he said.

Though some on the left are still uncertain about how to best navigate the fraught politics of transgender issues, there’s an emerging consensus on the right. The case of what happened to Gov. Kristi Noem of South Dakota, a rising star in the Republican Party, is instructive.

In March 2021, Ms. Noem declined to sign a bill passed by her state’s Republican-controlled legislature that would have banned transgender girls from sports teams from kindergarten through college. Conservative groups accused her of bowing to “socially left-wing factions.” Tucker Carlson of Fox News, in a tense interview with Ms. Noem, implied she was bowing to “big business” in refusing to sign the bill.

“There’s a real political effort now that will extract a punishment from you if you betray the social conservatives,” said Frank Cannon, a founder of the American Principles Project. He said the episode with Ms. Noem “sent a signal to every other governor in the country.”

Eleven months later, the governor appeared to have received the message, signing a similar version of the bill in the interest, she said that day, of “fairness.”