(The Center Square) – The U.S. House voted Thursday to pass a bill codifying protections for same-sex marriages.

The vote was 258-169 as nearly 40 Republicans sided with the bill, which has already passed the Senate and will soon head to the desk of President Joe Biden, who is expected to sign the legislation into law.

Rep. Nancy Pelosi, D-Calif., who is stepping down from her role as House Speaker, called the bill “a major victory for freedom, dignity and equality by enshrining into federal law marriage equality for same-sex and interracial couples.”

As The Center Square previously reported, U.S. Sen. Tammy Baldwin, D-Wisc., helped lead the effort in the Senate. Her office said the legislation would “require the federal government to recognize a marriage between two individuals if the marriage was valid in the state where it was performed.”

The legislation would “guarantee that valid marriages between two individuals are given full faith and credit, regardless of the couple’s sex, race, ethnicity or national origin, but the bill would not require a State to issue a marriage license contrary to state law.”

The U.S. Supreme Court’s overturning of the landmark Roe v. Wade abortion ruling motivated this legislative effort. Some Democrats said same-sex marriage protections the court ruled on during the Obama administration could be at risk.

In 2015, the U.S. Supreme court ruled in Obergefell v. Hodges in favor of same-sex marriage, requiring states to allow those unions under the law. But the high court’s overturning of Roe v. Wade earlier this year motivated Democrats in particular, who feared that the Obergefell precedent protecting same-sex marriages could be overturned.

The legislation in question repeals the federal Defense of Marriage Act, but without this legislation state laws preventing same-sex marriage are still on the books in some states and would take effect if Obergefell were ever overturned.