WASHINGTON (AP) — The House is set to give final approval Thursday to legislation protecting same-sex marriages in federal law, a monumental step in a decadeslong battle for nationwide recognition of such unions that reflects a stunning turnaround in societal attitudes.

A law requiring all states to recognize same-sex marriages would come as a a relief for hundreds of thousands of couples who have married since the Supreme Court’s 2015 decision that legalized those marriages nationwide. The bipartisan legislation would also protect interracial unions by requiring states to recognize legal marriages regardless of “sex, race, ethnicity, or national origin.”

President Joe Biden backs the bill and said he will “promptly and proudly” sign it into law.

Democrats have moved the bill quickly through the House and Senate since the Supreme Court’s June decision that overturned the federal right to an abortion. That ruling included a concurring opinion from Justice Clarence Thomas that suggested same-sex marriage should also be reconsidered.

Roused to action by the court, the House passed a bill to protect the same-sex unions in July with the support of 47 Republicans, a robust and unexpected show of support that kick-started serious negotiations in the Senate. After months of talks, the Senate passed the legislation last week with 12 Republican votes.

House Speaker Nancy Pelosi, D-Calif., has said she is happy that the marriage legislation will be one of her last acts in leadership before stepping aside in January. “I’m so excited,” she said of the legislation, which she said will ensure that “the federal government will never again stand in the way of marrying the person you love.”

The legislation would not require states to allow same-sex couples to marry, as the Obergefell ruling now does. But it would require states to recognize all marriages that were legal where they were performed and it would protect current same-sex unions if the court’s 2015 Obergefell v. Hodges decision were to be overturned.

While it’s not everything advocates may have wanted, passage of the legislation represents a watershed moment. Just a decade ago, many Republicans openly campaigned on blocking same-sex marriages; today more than two-thirds of the public support them.

Democrats in the Senate, led by Wisconsin’s Tammy Baldwin and Arizona’s Kyrsten Sinema, slowly won over key Republican votes by negotiating an amendment that would clarify that the legislation does not affect the rights of private individuals or businesses that are already enshrined in current law. The amended bill would also make clear that a marriage is between two people, an effort to ward off some far-right criticism that the legislation could endorse polygamy.

In the end, several religious groups, including The Church of Jesus Christ of Latter-day Saints, came out in support of the bill. The Mormon church said it would support rights for same-sex couples as long as they didn’t infringe upon religious groups’ right to believe as they choose.

Still, most Republicans opposed the legislation and some conservative advocacy groups lobbied aggressively against it in recent weeks, arguing that it doesn’t do enough to protect those who want to refuse services for same-sex couples.

“Marriage is the exclusive, lifelong, conjugal union between one man and one woman, and any departure from that design hurts the indispensable goal of having every child raised in a stable home by the mom and dad who conceived him,” the Heritage Foundation’s Roger Severino, vice president of domestic policy, wrote in a recent blog post arguing against the bill.

In Congress, as public sentiment has shifted, Republicans have largely shied away from making that argument. On the House floor Wednesday night, a handful of Republicans voiced opposition over the legislation for process reasons — saying that it hadn’t gotten a full hearing in the House — or by arguing that the religious liberty provisions added by the Senate weren’t enough.

The bill’s supporters will be watching to see whether the 47 Republicans who previously backed the legislation will stick with it, and whether they could gain more votes especially now that it includes the additional religious liberty provisions negotiated by Senate Republicans. Heritage and other groups have been pushing Republicans who support the bill to switch their position.

The almost four dozen Republicans who supported the bill this summer represented a wide range of the GOP caucus — from more moderate members to Pennsylvania Rep. Scott Perry, the chair of the conservative hard-right House Freedom Caucus, and New York Rep. Elise Stefanik, the No. 3 House Republican. All four Republican members of Utah’s congressional delegation also supported the legislation. House Republican leader Kevin McCarthy voted against the measure.

The votes come as the LGBTQ community has faced violent attacks, such as the shooting earlier this month at a gay nightclub in Colorado that killed five people and injured at least 17.

“We have been through a lot,” said Kelley Robinson, the incoming president of the advocacy group Human Rights Campaign. But Robinson says the votes show “in such an important way” that the country values LBGTQ people.

“We are part of the full story of what it means to be an American,” said Robinson, who was inside the Senate chamber for last week’s vote with her wife and young son. “It really speaks to them validating our love.”

The vote was personal for many senators, too. The day the bill passed their chamber, Senate Majority Leader Chuck Schumer was wearing the tie he wore at his daughter’s wedding to another woman. He recalled that day as “one of the happiest moments of my life.”

Baldwin, the first openly gay senator who has been working on gay rights issues for almost four decades, tearfully hugged Schumer as the final vote was underway. She tweeted thanks to the same-sex and interracial couples who she said made the moment possible.

“By living as your true selves, you changed the hearts and minds of people around you,” she wrote.