A ban on same-sex marriages in California has been ruled unconstitutional by a federal judge, marking a major turning point in a controversial debate that has divided America.

In a politically charged judgment, US District Court Chief Judge Vaughn Walker handed gay rights advocates a critical victory after a 13-day hearing.

Crucially, he also ordered that the ban, approved by the voters and known as Proposition 8, should be lifted immediately, allowing gay and lesbian couples to marry while the case moves to a higher court for appeal.

Proposition 8 supporters had argued to keep the ban in place pending the outcome of their appeal. In a 136-page ruling, Walker said the lawsuit challenging the ban "demonstrated by overwhelming evidence" that it violates due process amid equal-protection rights under the US constitution.

"Proposition 8 fails to advance any rational basis in singling out gay men and lesbians for denial of a marriage licence," he said. "Indeed, the evidence shows Proposition 8 does nothing more than enshrine in the California constitution the notion that opposite-sex couples are superior to same-sex couples".

His ruling was greeted by cheers from some 70 same-sex marriage supporters outside the courthouse in San Francisco as they waved US flags and a large rainbow-striped flag – the symbol of the gay rights movement.

The debate has polarised America, dividing the public and the political establishment. Opponents, including many religious conservatives, see same-sex marriage as a threat to the "traditional family".

The ban was passed with 52% of the vote after the ballot was sponsored by the group Protect Marriage in what has been classed the most expensive political campaign on a social issue in US history.

Meanwhile, civil libertarians have argued it is a battle for equal rights.

The case will go to appeal to the 9th US Circuit Court of Appeals, and thereafter, possibly to the Supreme Court. The lawsuit was filed by two gay couples who claimed the ban violated their civil rights.

In all 18 witnesses gave evidence in the case, with academic experts testifying on topics ranging from the fitness of gay parents and religious views on homosexuality, to the historical meaning of marriage and the political influence of the gay rights movement.

Former US Solicitor General Theodore Olson, delivering the closing argument for the opponents of the ban, said that tradition or fears of harm to heterosexual unions were not legally sufficient grounds on which to discriminate against gay couples.

Meanwhile the defence lawyers called just two witnesses, arguing that they did not need to present expert testimony because US Supreme Court precedent was on their side. They argued that gay marriage was an experiment with unknown social consequences and should be left to the voters to decide to accept or reject it.

Religious and conservative groups, who had sponsored the ban, said that cultures around the world, as well as previous court decisions and Congress all accepted "the common sense belief that children do best when they are raised by their own father and mother. "

The governor of California, Arnold Schwarzenegger, and the California Attorney, refused to support Proposition 8. "For the hundreds of thousands of Californians in gay and lesbian households who are managing their day-to-day lives, this decision affirms the full legal protections and safeguards I believe everyone deserves," Schwarzenegger said in a statement released by his office.

"It provides an opportunity for all Californians to consider our history of leading the way to the future …of treating all people and their relationships with equal respect and dignity,." Schwarzenegger said.

"Today's decision is by no means California's first milestone, nor our last, on America's road to equality and freedom for all people."

The verdict is the second in a federal gay marriage case to fall down in recent weeks. In Massachusetts last month a federal judge ruled that legally married gay couples in the state had been wrongly denied the federal financial benefits of marriage because of a law preventing the US government from recognising same-sex unions.

Currently same-sex couples can only legally marry in Massachusetts, Iowa, Connecticut, Vermont, New Hampshire and Washington DC.