An abortion rights demonstrator waves a Pride flag during a rally in front of the US Supreme Court in Washington in June 2022

Washington (AFP) - The US Congress on Thursday passed landmark legislation to protect same-sex marriage under federal law, and President Joe Biden has vowed to quickly sign the measure.

The vote in the House of Representatives saw 39 Republicans join a united Democratic majority in a rare show of bipartisanship, provoking loud cheers on the floor less than 10 days after the Senate passed the same bill.

“Today, Congress took a critical step to ensure that Americans have the right to marry the person they love,” Biden said in a statement.

He said the bipartisan vote would “give peace of mind to millions of LGBTQI+ and interracial couples who are now guaranteed the rights and protections to which they and their children are entitled.”

The conservative-led Supreme Court in June overturned longstanding abortion rights, prompting lawmakers of both parties to move to prevent the court from taking away same-sex marriage rights, as some feared it might do.

The House had earlier approved legislation similar to the Senate’s, but needed Thursday’s vote to reconcile minor differences.

Biden has dubbed marriage equality one of his legislative priorities and has said he will “promptly and proudly” sign the bill into law.

Democrats and others saluted the historic vote.

Speaker of the House Nancy Pelosi and Senate Majority Leader Chuck Schumer pose as bipartisan Senate and House members participate in a bill enrollment ceremony for the 'Respect For Marriage Act' on Capitol Hill

“I began my career fighting for LGBTQ communities,” outgoing House Speaker Nancy Pelosi tweeted on Thursday, “and now, one of the final bills that I will sign as Speaker will ensure the federal government never again stands in the way of marrying the person you love.”

The new legislation, known as the Respect for Marriage Act, does not require states to legalize same-sex marriage but does require them to recognize a marriage so long as it was valid in the state where it was performed.

- ‘Wrong way to go’ -

It repeals previous legislation defining marriage as a union between a man and a woman, and also protects interracial couples by requiring states to recognize legal marriages without regard to “sex, race, ethnicity or national origin.”

Public acceptance of same-sex marriage has grown dramatically in recent decades, with polls now showing a strong majority of Americans supporting it.

But some conservatives and the religious right remain opposed.

“I think this is the wrong way to go,” conservative Republican Jim Jordan said shortly before the vote.

House Democrats had worked with urgency to get the bill passed while they still control Congress. Republicans won a narrow majority in the chamber in midterm elections in November and will take control there in January, while Democrats retain narrow control of the Senate.

The Supreme Court in a 2015 decision legalized same-sex marriages. Hundreds of thousands of couples have married since then.