The U.S. Supreme Court overturned Wednesday a federal law that prevented the federal government from recognizing gay marriages in states where they're legal, but declined to rule on the constitutionality of state bans on same-sex marriage.

In the case challenging the federal Defense of Marriage Act (DOMA), which defines marriage as between a man and a woman for federal purposes, the Court struck down the law 5-4. The United States v. Windsor ruling ensures that married same-sex couples in the 12 states (plus the District of Columbia) that have legalized those nuptials will have access to federal benefits.

MAP: See which states legalize same-sex marriage.

"DOMA singles out a class of persons deemed by a State entitled to recognition and protection to enhance their own liberty," Justice Anthony Kennedy wrote in the decision. He asserted that the law violated same-sex couples' equal protection rights under the Constitution.

The Court's liberal block (Justices Stephen Breyer, Ruth Bader Ginsburg, Sonia Sotomayor and Elena Kagan) joined in Kennedy's opinion. The conservative justices (Chief Justice John Roberts, Antonin Scalia, Samuel Alito and Clarence Thomas) dissented.

In the case challenging California's voter-approved ban on gay marriage, the Court decided that it did not have jurisdiction to hear the case. During oral arguments earlier this year, the Court questioned whether it could consider the case because California officials had declined to defend the state law in court.

Instead, private supporters of the ballot initiative had taken up the case to defend it, but the Court ruled Wednesday 5-4 that they did not have the legal standing to do so. Roberts wrote the opinion, joined by Scalia, Ginsburg, Breyer and Kagan.

"We have never before upheld the standing of a private party to defend the constitutionality of a state statute when state officials have chosen not to," Roberts wrote. "We decline to do so for the first time here."

The ruling vacates the decision of the federal appeals court, which had overturned the ban, because the ban's defenders lack standing to appeal. In effect, it makes same-sex marriage legal again in California because the same-sex couples who challenged the ban won in the U.S. district court before the case was appealed. It does not, however, affect gay marriage bans in the 30-plus states that have approved them.

MAP: See which states ban same-sex marriage.

The Court considered two cases concerning gay marriage this year: one challenging DOMA, which prohibits the federal government from awarding federal benefits to same-sex couples, even those legally married under state law; and one challenging the constitutionality of California's Proposition 8, a voter-approved state law that banned same-sex nuptials.

Both plaintiffs alleged that the California law and the federal law violated their constitutional right to equal protection. The lower courts in both cases had sided with the plaintiffs, ruling that gay couples should have the same rights to marry as heterosexual couples.

The decision in United States v. Windsor appears below.