The House on Thursday passed a bill to codify federal recognition of same-sex and interracial marriages, which now goes to President Joe Biden's desk for his signature.
The Respect for Marriage Act passed with bipartisan support in a 258-169 vote. Thirty-nine Republicans joined Democrats in voting yes on the measure.
The legislation passed with cheers and hugs on the floor. Former Rep. Barney Frank, an openly gay Democrat who has long fought for marriage equality, was present for the vote.
MORE: How Congress achieved a historic breakthrough on gay marriageHouse Speaker Nancy Pelosi, Senate Majority Leader Chuck Schumer, Rep. David Cicilline, Sen. Tammy Baldwin, Rep. Jerry Nadler and Republican Sen. Susan Collins held a bill enrollment ceremony celebrating the bill's passage.
"What a great day," Pelosi said at the ceremony, thanking her colleagues for their support. "At last we have history in the making, but not only are we on the ride sight of history, we are on the right side of the future: expanding freedom in America."
Pelosi, who is leaving her post as House Democratic leader, has said she is "particularly happy" the Respect for Marriage Act will be one of the last bills she signs in her role.
"Once signed into law, the Respect for Marriage Act will help prevent right-wing extremists from upending the lives of loving couples traumatizing kids across the country, and turning back the clock on hard-won progress," Pelosi said in a floor speech ahead of the vote.
Biden has said he's prepared to sign the measure after it passed the House. In a statement Thursday, Biden celebrated Congress for taking a "critical step to ensure that Americans have the right to marry the person they love."
"The House's bipartisan passage of the Respect for Marriage Act -- by a significant margin -- will 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," Biden said in a statement.
Ensuring same-sex marriage rights are protected between states became a top priority for Democrats in light of the Supreme Court's June decision to overrule its precedent in 1973's Roe v. Wade guaranteeing a constitutional right to abortion.
Justice Clarence Thomas indicated in a concurring opinion at the time that he would like to see the court reverse the 2015 ruling Obergefell v. Hodges guaranteeing the national right to same-sex marriage, which was decided on similar grounds as Roe.
MORE: Senate approves historic legislation to protect same-sex marriagesThe Respect for Marriage Act will not codify Obergefell and set a national requirement that all states must license same-sex marriages. But it will require individual states to recognize a same-sex (or interracial) marriage that was lawfully performed in another state.
The Senate passed the bill last week, 61-36 -- marking a victory for Democrats during the lame-duck after months of negotiations with Republicans. Twelve members of the GOP voted in support of the legislation.
Schumer at Thursday's bill enrollment ceremony said the issue is personal for many in Congress. Schumer's daughter is married to her wife.
"Thanks to the tireless advocacy of many -- many in this room -- and the dogged work by many of my colleagues, my grandchild will live in a world that will respect and honor their mothers' marriage," he said. "So yes, this is about millions of LGBTQ Americans in the country but countless other lives of children and families will also be impacted."
The House passed a similar version of this legislation earlier this year, with 47 Republicans supporting it. The Senate version includes new language to ease some GOP concerns about religious freedom.
ABC News' Allison Pecorin, Will Steakin and Gabe Ferris contributed to this report.