The court, however, fell short of a landmark ruling endorsing a fundamental right for gay people to marry.
The two cases, both decided on 5-4 votes, concerned the constitutionality of a key part of a federal law, the Defense of Marriage Act (DOMA), that denied benefits to same-sex married couples and a California state law enacted in 2008, called Proposition 8, that banned gay marriage.
Gay marriage is an issue that stirs cultural, religious and political passions in the United States as elsewhere. Gay marriage advocates celebrated outside the courthouse. An enormous cheer went up as word arrived that DOMA had been struck down. "DOMA is dead!" the crowd chanted, as couples hugged and cried.
"Our marriage has not been recognized until today," said Patricia Lambert, 59, who held her wife, Kathy Mulvey, 47. A South African, Lambert said she no longer would have to worry about being forced to leave the country if her work visa expired.
The court struck down the federal law as a violation of the U.S. Constitution's guarantee of equal protection under the law but ducked a ruling on Proposition 8 by finding that supporters of the law did not have standing to appeal a federal district court ruling that struck the law down.
While the ruling on DOMA was clear-cut, questions remained about what exactly the Proposition 8 ruling will mean on the ground. There is likely to be more litigation over whether the district court ruling applies statewide.
After hearing of the California ruling outside the courthouse, Anthony Romero, the executive director of the American Civil Liberties Union, said the fight for gay marriage would head back to the states.
"We take it to the states—state by state, legislature by legislature, governor by governor, and constitutional amendment by constitutional amendment," he said.
In the DOMA case, Justice Anthony Kennedy wrote for the majority that the federal law, as passed by Congress in 1996, violated the U.S. Constitution's guarantee of equal protection.
"The federal statute is invalid, for no legitimate purpose overcomes the purpose and effect to disparage and to injure those whom the state, by its marriage laws, sought to protect in personhood and dignity," Kennedy wrote.
Kennedy, often the court's swing vote in close decisions, also said the law imposes "a stigma upon all who enter into same-sex marriages made lawful by the unquestioned authority of the states."
Chief Justice John Roberts and Justice Antonin Scalia both wrote dissenting opinions.
Roberts himself wrote the Proposition 8 opinion, ruling along procedural lines with the court split in an unusual way.
Twelve of the 50 states and the District of Columbia recognize gay marriage. Three of those dozen—Delaware, Minnesota and Rhode Island—legalized gay marriage this year.
Section 3 of the Defense of Marriage Act limited the definition of marriage as between a man and a woman for the purposes of federal benefits. By striking down Section 3, the court cleared the way to more than 1,100 federal benefits, rights and burdens linked to marriage status.
As a result of Wednesday's ruling, Edith Windsor of New York, who was married to a woman and sued the government to get the federal estate tax deduction available to heterosexuals when their spouses pass away, will be able to claim a $363,000 tax refund.
President Barack Obama is the first sitting U.S. president to endorse gay marriage but he had long asserted that same-sex marriage was a matter for the states to handle. At the last minute, however, his administration decided to enter the California dispute and argue that federal guarantees of constitutional equality forbid states from limiting marriage to heterosexuals.
Numerous public figures including former President Bill Clinton, who in 1996 signed the DOMA law, and prominent groups including the American Academy of Pediatrics have come out this year in support of same-sex marriage and gay civil rights.
Individual members of Congress—Democrats and Republicans—also voiced new support for gay marriage.
While more developments lie ahead, the legal fight over gay marriage already constitutes one of the most concentrated civil rights sagas in U.S. history. Just 20 years ago the Hawaii Supreme Court ruled that its state constitution could allow gay marriage, prompting a nationwide backlash and spurring Congress and a majority of states, including Hawaii, to pass laws defining marriage as between only a man and woman.
In 2003, when the top court of Massachusetts established a right to same-sex marriage under its constitution, the action triggered another backlash as states then adopted constitutional amendments against such unions. Five years later, the tide began to reverse, and states slowly began joining Massachusetts in permitting gays to marry.
The cases are United States v. Windsor, U.S. Supreme Court, No. 12-307 and Hollingsworth v. Perry, U.S. Supreme Court, No. 12-144.