The court invalidated a provision of the federal Defense of Marriage Act that has prevented married gay couples from receiving a range of tax, health and retirement benefits that are generally available to married people. The vote was 5-4.
Justice Anthony Kennedy wrote the majority opinion.
Same-sex marriage has been adopted by 12 states and the District of Columbia. Another 18,000 couples were married in California during a brief period when same-sex unions were legal there.
The Supreme Court also cleared the way for same-sex marriage in California by holding that defenders of California's gay marriage ban did not have the right to appeal lower court rulings striking down the ban.
The court's 5-4 vote Wednesday leaves in place the initial trial court declaration that the ban is unconstitutional. California officials probably will rely on that ruling to allow the resumption of same-sex unions in about a month's time.
The high court itself said nothing about the validity of gay marriage bans in California and roughly three dozen other states.
The outcome was not along ideological lines.
Chief Justice John Roberts wrote the majority opinion, joined by Justices Ruth Bader Ginsburg, Stephen Breyer, Elena Kagan and Antonin Scalia.
"We have no authority to decide this case on the merits, and neither did the 9th Circuit," Roberts said, referring to the federal appeals court that also struck down Proposition 8.
Four justices, Anthony Kennedy, Samuel Alito, Clarence Thomas and Sonia Sotomayor, said the court should have decided the constitutional question that was before it.
Chanting "DOMA is Dead," supporters of same-sex marriage burst into cheers Wednesday at news of the Supreme Court's decision invalidating part of a law denying gay marriage partners the same federal benefits heterosexual couples enjoy.
Sarah Prager, 26, cried when she heard the news standing outside the court. Prager married her wife in Massachusetts in 2011 and now lives in Maryland.
"I'm in shock. I didn't expect DOMA to be struck down," she said through tears and shaking. Prager was referring to the Defense of Marriage Act, signed into law by President Bill Clinton in 1996, which was aimed at preserving the legal definition of marriage as between a man and a woman.
A large crowd had thronged to the high court's plaza earlier to await not only the decision on DOMA, but also a ruling on whether a constitutional amendment in California prohibiting gay marriage could stand the test of challenge.