WASHINGTON — The U.S. Supreme Court today snatched away from the federal government the power to ban same-sex marriages, shifting the contentious struggle to the states to decide whether they will recognize gay marriages.

With a huge boisterous crowd waiting outside the court, the justices by a 5-4 vote struck down a 1996 federal law known as the Defense of Marriage Act that defined marriage as only between a man and a woman.

In a companion ruling, the justices ruled 5-4 to dismiss a challenge brought by supporters of a California referendum in 2008 that banned same-sex marriage. With their ruling, the justices let stand a 2010 decision by a federal judge in California that the referendum violated the U.S. Constitution, thus allowing same-sex marriage to resume in that state.

The rulings are a major victory for supporters of same-sex marriage. Even though the court’s decision allows the states to determine their marriage laws, it is clear that five justices — Anthony Kennedy, Ruth Bader Ginsburg, Stephen Breyer, Elena Kagan and Sonia Sotomayor — have deep reservations about state or federal laws that ban same-sex marriage.

The decision is likely to energize opponents of the 2004 ban on same-sex marriage in Ohio who are trying to gather signatures to place a repeal on next year’s ballot. It also injects some doubt into whether the current Supreme Court would approve the Ohio ban.

In his dissent, Justice Antonin Scalia warned that “by formally declaring anyone opposed to same-sex marriage an enemy of human decency, the majority arms well every challenger to a state law restricting marriage to its traditional definition.’’

In invalidating the 1996 federal law, Kennedy concluded the government had created “second-tier marriage’’ for gay couples married in 12 states and District of Columbia which recognize same-sex marriage.

“The differentiation demeans the couple whose moral and sexual choices the Constitution protects and whose relationship the state has sought to dignify,’’ Kennedy wrote. “And it humiliates tens of thousands of children now being raised by same-sex couples.’’

Joining Kennedy to form the majority were Kagan, Sotomayor, Ginsburg and Breyer. Chief Justice John Roberts and Justices Scalia, Samuel Alito and Clarence Thomas dissented.

Marc Spindelman, a law professor at the Moritz College of Law at Ohio State University, said while the ruling on its face appears to order the federal government to simply defer to states that allow same-sex marriage, the ruling’s broad language gives advocates of marriage equality a “powerful new tool” that may help them make the case against state bans of gay marriage.

The ruling “provides a new legal basis for saying state bans on same-sex marriage are unconstitutional,” he said.

The 1996 federal law signed by President Bill Clinton — known as the Defense of Marriage Act — defined marriage as the union of one man and one woman. Because the federal government under the law does not recognize same-sex marriage, the government can deny one of the spouses Social Security death benefits or force him or her to pay the estate tax.

The law was the reason the Internal Revenue Service informed Edith Windsor, 84, of New York City, that she owed $363,063 in estate taxes after the 2009 death of her female partner, Thea Spyer.

Windsor and Spyer had been legally married in Canada in 2007, but their marriage was not recognized by the federal government. Had Windsor been a man, she would have received Spyer's estate tax-free.

A federal judge and a three-judge panel of the U.S. Court of Appeals for the 2nd Circuit ruled in Windsor's favor, concluding that the federal law discriminated against her.

In his dissent in the Windsor case, Scalia argued the justices should have simply let stand the lower court rulings without addressing the broader question of same-sex marriage and federal law.

In the second case, a completely different judicial lineup concluded that supporters of the California ban on same-sex marriage had not shown they had been harmed by a lower court decision in 2010 to invalidate the referendum.

Roberts, who wrote the opinion, was joined by Kagan, Breyer, Ginsburg and Scalia, while Kennedy, Thomas, Sotomayor and Alito dissented.

Sen. Sherrod Brown, D-Ohio, who voted against the Defense of Marriage Act when he was a House member, called the rulings “great news for Ohio.”

Sen. Rob Portman, R-Ohio, who voted for the act, but who endorsed gay marriage earlier this year after his son Will came out as a gay, said he had hoped the federal law would be repealed by Congress rather than the high court. But he said he agreed with the court that marriage laws should “remain in the hands of the states.”

“I believe that gay couples deserve the opportunity to marry, but I believe change should come about through the democratic process in the states, through the process of citizen persuading fellow citizen that civil marriage should be allowed."

Crowds began lining up in front of the Supreme Court in anticipation of rulings on same sex marriage Tuesday night, with many camping out in hopes of receiving a chance to witness the rulings inside the Court. Oscar Soto of Reston, Va., arrived at the Court at 6 a.m. and described the early morning atmosphere as one of quiet anticipation.

As people received the “golden tickets” to get inside, “some of them were even crying because they couldn’t believe they got in and would be there for such a historic moment,” Soto said.

Grace Reinke, a student at Louisiana State University, said of the experience, “It was insane. It was crazy and excited and really happy, and I’ve probably never seen anything like it in my life.”

Not everyone in the crowd was thrilled with the rulings.

Reverend Rob Schenck, chairman of the Evangelical Church Alliance, one of the oldest associations of independent clergy in the nation, said, “The clergy, churches and communities I represent today oppose the social redefinition of marriage.” He said “biblical truth does not change by the vote of any majority, including a majority of this Court.”