However, Walker ordered the ban to remain in place until he decides on a request by supporters of the ban for it to stay intact pending appeal, leaving gay men and lesbian couples unable to marry for now.

Legal challenge

The case against Proposition 8, a state constitutional amendment defining marriage as between a man and a woman, marks the first challenge in federal court to a state law barring same-sex matrimony.

"Any marriage ban based on moral disapproval of gays would fall under[Walkers'] reasoning"

Margaret Russell, law professor, Santa Clara University

Supporters of the ban, which California voters passed 52.5 per cent to 47.5 per cent in November 2008 after one of the most expensive ballot-measure campaigns in US history, expressed confidence they would ultimately prevail.

"There aren't five votes on the Supreme Court for gay marriage," Maggie Gallagher, chair of the National Organisation for Marriage, said of the high court's conservative 5-4 majority.

Legal scholars said the decision has wide implications for nearly 40 states with similar laws, making it more difficult to defend those measures in court on the basis of moral grounds or social tradition.

Outside the federal courthouse in San Francisco, a cheer went up among a group of about 70 same-sex marriage supporters carrying small US flags, as a large rainbow-striped flag – the symbol of the gay rights movement – waved overhead.

Arnold Schwarzenegger, the governor of California who has said he personally supports gay marriage but would abide by the will of voters and the courts, said the decision "affirms the full protections and safeguards I believe everyone deserves".

A brief statement from the White House said that Barack Obama, the US president, "has spoken out in opposition to Proposition 8 because it is divisive and discriminatory".

Split opinion

The highly anticipated ruling marked a major turning point in an emotionally charged social debate that has sharply divided the American public and its political establishment.

Gay rights advocates and civil libertarians have cast the legal battle as a fight for equal rights, while opponents - including many religious conservatives - see same-sex marriage as a threat to the traditional family.

"I'm thrilled," Steven Ray Davis, a gay marriage supporter, said outside the court. "We still have a long way to go."

Wednesday's decision has no bearing on 18,000 gay and lesbian couples who were legally married in California from June 2008 – when a state Supreme Court ruling overturned an earlier ban – and November 2008 when Proposition 8 was passed.

Early last month, a federal judge in the state of Massachusetts ruled that a 1996 federal law, which denies federal recognition of same-sex marriages, even in states where it is allowed, was unconstitutional.

Margaret Russell, a law professor at Santa Clara University, told the Reuters news agency that if Walker's opinion is sustained, it would have broad consequences beyond California.

"Any marriage ban based on moral disapproval of gays would fall under that reasoning," she said.