Media playback is unsupported on your device Media caption Hot tempers and dance parties outside US Supreme Court

A US law that defines marriage as between a man and a woman only has been sharply criticised by Supreme Court justices at a landmark hearing.

A judge considered the court's swing vote joined four liberal colleagues in questioning the constitutionality of the Defense of Marriage Act (Doma).

Legal analysts speculated that the law, which denies various federal benefits to gay couples, may be struck down.

A ruling on the case is expected by the end of June.

At the same time, America's highest court is expected to issue a decision about California's gay marriage ban, which it debated a day earlier.

For nearly two hours on Wednesday, the nine justices in Washington DC grilled lawyers on the constitutionality of Doma, with five of them making sceptical remarks about the 1996 law.

'Skim-milk marriage'

Doma denies married gay and lesbian couples the same federal rights, such as tax breaks and welfare benefits, granted to heterosexual couples.

Analysis A first look at the justices' comments indicates a classic liberal-conservative split. The four liberal justices seem to lean toward overturning Doma on legal equality grounds - that it is discriminatory. The conservatives seem more concerned about why the Obama administration is not defending a federal law. And in the middle, as is so often the case, is Justice Anthony Kennedy. His beef with Doma appears to be that it intrudes too deeply into states' rights. He has warned of the "risks" of federal overreach into what is the states' prerogative. There is still a chance that the court will decide it has no business hearing the case. But if the four liberals are joined by Justice Kennedy, Doma will bite the dust. It may not be the prettiest judgement intellectually, but for same-sex marriage campaigners, it will do.

Justice Anthony Kennedy, seen as the swing vote between liberal and conservative justices, said he was "troubled" by how the law appeared to intrude on states' authority to define marriage as they saw fit.

"The question is whether or not the federal government under a federalism system has the authority to regulate marriage," he said.

Justice Ruth Bader Ginsburg, a liberal, suggested the law created a two-tiered system of wedlock.

"There are two kinds of marriage: full marriage and the skim-milk marriage," she said.

Her colleague, Elena Kagan, said Doma was "infected by animus, fear and dislike".

Justice Sonia Sotomayor asked: "What gives the federal government the right to be concerned at all about what the definition of marriage is?"

The Obama administration refused to defend Doma in court, having deemed it unconstitutional. Instead, a group of House Republicans hired a lawyer to argue in favour of the law.

Chief Justice John Roberts questioned why President Obama did not have "the courage of his convictions" to stop enforcing the law.

Signed by President Bill Clinton, Doma has already been ruled unconstitutional by several lower courts.

Image copyright Getty Images Image caption In her brief, Edith Windsor, left, said for much of her life she could not live openly as a gay woman

The case against Doma was originally brought by New Yorker Edith Windsor, 83, who was required to pay more than $350,000 (£220,000) of federal inheritance taxes after the 2009 death of her wife, Thea Spyer.

Outside the court on Wednesday, Ms Windsor said: "The justices were gentle, I didn't feel any hostility. I think it's going to be good."

On Tuesday the Supreme Court heard arguments in another gay marriage case, on the legality of a California constitutional amendment banning same-sex unions.

Proposition 8 was approved by California voters in a referendum in 2008.

Supporters of gay marriage are hoping the court could erase bans on same-sex marriages nationwide.

But legal analysts say the justices' comments on Tuesday did not seem to promise such a sweeping ruling.

Currently, nine US states and Washington DC permit same-sex marriage. Twelve other states allow civil unions or domestic partnerships that provide varying degrees of state marriage benefits.

Recent opinion polls have shown a steady rise in support for same-sex marriage in the US, together with declarations in favour of it by political figures such as Hillary Clinton.