In a major move, the US House of Representatives passed the Respect for Marriage Act, a legislation aimed to protect same-sex and interracial marriage.
The bill will now go to President Joe Biden, who is reportedly looking forward to signing it into law.
The bill passed with a 258-169 vote in the lower chamber. While all of the chamber's Democrats voted in its favour, 39 Republicans too favoured the bill.
While one voted "present", the other 169 voted against it.
The US Senate passed a bill in November end with a final vote of 61-36. All members of the Democratic caucus and 12 Republicans had backed the bill then.
An earlier version of the bill passed in July but had won the support of 47 House Republicans then.
But eight switched sides on Thursday while one, Rep Burgess Owens of Utah, changed his position to present.
The Respect for Marriage Act would allow the federal government and states to recognize same-sex and interracial marriages performed legally.
The version that was passed on Thursday had an amendment that provided additional protections for religious liberty and faith-based nonprofits, something Republicans had sought.
Once passed, the legislation can bar states from rejecting the validity of out-of-state marriages on the basis of sex, race or ethnicity.
However, it would not stop states from blocking same-sex or interracial marriages if the Supreme Court allowed them to do so.
The bill will also repeal a 1996 U.S. law called the Defense of Marriage Act (DOMA) which denied federal benefits to same-sex couples.
The DOMA was signed into law by then-President Bill Clinton, but the Supreme Court had later invalidated the key provisions of DOMA in two landmark rulings, United States v.
Windsor and Obergefell v. Hodges in 2013 and 2015, respectively.
However, the bill gained traction after conservative Supreme Court Justice Clarence Thomas suggested earlier the year that the Supreme court should reconsider rights like birth control and same sex marriage in future decisions.
Thomas's suggestion came right after the court overturned Roe v. Wade and the federal right to an abortion.
The fear that the Supreme Court's conservative majority could repeal same-sex marriage nationwide had prompted advocates to push Congress to enshrine those rights into law.