House Speaker Nancy Pelosi of Calif., announces final passage of the bill with protections for same-sex marriages, on the House Floor on Thursday, Dec. 8, 2022, in Washington.
CNN  — 

The House voted to pass legislation on Thursday to protect same-sex and interracial marriage, the last step before the measure goes to President Joe Biden for his signature and becomes law.

The House vote was 258 to 169 with 39 Republicans joining the Democrats voting in favor. Loud applause broke out in the chamber when the vote was gaveled to a close.

While the bill would not set a national requirement that all states must legalize same-sex marriage, it would require individual states to recognize another state’s legal marriage.

The push for a vote on federal legislation protecting same-sex marriage rapidly gained momentum after the Supreme Court in June overturned its landmark Roe v. Wade decision.

The bill, called the Respect for Marriage Act, passed the Senate with a vote of 61 to 36 last week. The bill was supported by all members of the Senate Democratic caucus and 12 Republicans.

In the event the Supreme Court might overturn its 2015 Obergefell v. Hodges decision that legalized same-sex marriage, a state could still pass a law to ban same-sex marriage, but that state would also be required to recognize a same-sex marriage from another state.

House Speaker Nancy Pelosi wrote in an op-ed published to The Washington Post Wednesday she is “overjoyed” that one of the last bills she will help pass while she holds the title of speaker will be the legislation protecting same-sex marriage in the United States.

“Just as I began my career fighting for LGBTQ communities, I am overjoyed that one of the final bills I will sign as speaker will be the Respect for Marriage Act: ensuring the federal government will never again stand in the way of marrying the person you love,” she wrote in the op-ed.

President Joe Biden applauded Senate passage of the Respect for Marriage Act last week, saying in a statement: “For millions of Americans, this legislation will safeguard the rights and protections to which LGBTQI+ and interracial couples and their children are entitled.”

Biden added: “I look forward to welcoming them at the White House after the House passes this legislation and sends it to my desk, where I will promptly and proudly sign it into law.”

The Supreme Court’s move in June holding that there is no longer a federal constitutional right to an abortion immediately sparked controversy and criticism from liberal groups as well as concern that the court’s conservative majority could take aim at same-sex marriage in the future. Justice Clarence Thomas, for instance, when Roe v. Wade was overturned, explicitly called on the court to revisit the 2015 Obergefell v. Hodges decision that cleared the way for same-sex marriage nationwide.

The Supreme Court is currently considering a case that deals with the issue of LGBTQ rights and religious liberty.

Several conservative members of the Supreme Court seemed sympathetic on Monday to arguments from a graphic designer who seeks to start a website business to celebrate weddings but does not want to work with same-sex couples.

The conservative justices viewed the case through the lens of free speech and suggested that an artist or someone creating a customized product could not be forced by the government to express a message that violates her religious beliefs.

This story and headline have been updated with additional developments.

CNN’s Ali Zaslav, Ted Barrett and Ariane de Vogue contributed.