The broadest possible ruling would have given gay Americans the same constitutional right to marry as heterosexuals. The justices said nothing on that topic in either case.
The decisions Wednesday have no effect on the roughly three dozen states that do not allow same-sex marriage, including 29 that have enshrined the bans in their constitutions.
The federal marriage law, known by its acronym DOMA, had been struck down by several federal courts.
The justices chose for their review the case of 84-year-old Edith Windsor of New York, who sued to challenge a $363,000 federal estate tax bill after her partner of 44 years died in 2009.
Windsor, who goes by Edie, married Thea Spyer in 2007 after doctors told them Spyer would not live much longer. She suffered from multiple sclerosis for many years. Spyer left everything she had to Windsor.
Windsor would have paid nothing in inheritance taxes if she had been married to a man. And now she is eligible for a refund.
Associated Press writers Connie Cass, Jessica Gresko and Bethan McKernan contributed to this report. McKernan reported from New York.