Re-establishing California as the nation’s chief battleground for same-sex marriage, a San Francisco federal judge on Wednesday struck down the state’s latest attempt to outlaw gay nuptials and triggered a tempest by boldly declaring that gay and lesbian couples should have the immediate right to start walking down the aisle.

In a ruling expected to serve as the first draft in a drawn-out legal battle, Chief U.S. District Judge Vaughn Walker concluded that the voter-approved Proposition 8 tramples on the rights of gay and lesbian couples, has no social justification and is unconstitutional.

The judge’s ruling sent same-sex couples scrambling to local city halls and county clerks around the state in hopes of securing a marriage license. But they quickly discovered that the right to marry will continue to elude them for the time-being.

Walker agreed to put his ruling on hold until at least Friday to consider arguments on whether California should be barred from enforcing Proposition 8, a restriction that would allow same-sex couples to marry right away. The judge indicated he’s inclined to scrap Proposition 8 immediately, but legal experts predict a federal appeals court would then intervene and put same-sex marriages on hold while the legal struggle continues, possibly for years.

The judge’s ruling marked another remarkable turn in California’s six-year-old legal and cultural war over the right of same-sex couples to marry. Gay-rights groups hailed the decision and Proposition 8 supporters blasted it for thwarting the will of the voters. The ruling, which could ultimately force the U.S. Supreme Court to address the gay-marriage issue, was based on a historic trial in January in the first federal court test in the nation of a state’s right to forbid same-sex marriage.

In the coming months, it is likely to ripple into the political arena, from the midterm elections in Congress to California’s governor’s race, where Attorney General Jerry Brown has argued that Proposition 8 is unconstitutional and Republican rival Meg Whitman has supported the law.

In the meantime, supporters of Proposition 8 vowed to appeal Walker’s order to the 9th U.S. Circuit Court of Appeals. Prop. 8 backers said in court papers that a stay of Walker’s ruling is “essential to averting the harms that would flow from another purported window of same-sex marriage in California.”

While legal experts say it is hard to predict whether the 9th Circuit will uphold Walker’s ruling, they agree it may create too much uncertainty to void Proposition 8 until the case is fully resolved. Among other things, couples who might marry during the appeals process could see those unions dissolved if Walker is reversed. In 2004, when San Francisco Mayor Gavin Newsom married same-sex couples for a brief period, those licenses were invalidated by the state Supreme Court.

“If the 9th Circuit reverses Walker, then you have all this chaos,” said Vikram Amar, a UC Davis law professor. “I think the prudent course would be to issue a stay.”

In his 136-page ruling, Walker sided with two same-sex couples who challenged Proposition 8, which embedded a ban on gay marriage in the California constitution and wiped out a prior California Supreme Court ruling that briefly legalized same-sex nuptials across the state.

“Proposition 8 fails to advance any rational basis in singling out gay men and lesbians for denial of marriage licenses,” Walker wrote.

Reaction to the ruling was swift on both sides, as demonstrations rippled across the state from West Hollywood to San Francisco, where dozens of gay marriage supporters gathered outside the federal courthouse to await the release of the decision. A cheer went up when a Facebook posting said the law had been overturned, with people crying and kissing as they learned the news.

“For our entire lives, our government and the law have treated us as unequal,” said Berkeley resident Kristin Perry, one of the plaintiffs along with her partner, Sandy Stier. “This decision to ensure that our constitutional rights are as protected as everyone else’s makes us incredibly proud of our country.”

Same-sex marriage foes were outraged that Walker overturned the law, backed by voters in November 2008 by a 52 to 48 percent margin.

“We expected nothing different from Judge Vaughn Walker, given the biased way he conducted this trial,” said Brian Brown, president of the National Organization for Marriage. “With a stroke of his pen, Judge Walker has overruled the votes and values of 7 million Californians who voted for marriage as one man and one woman.”

The judge based his decision on weeks of testimony that unfolded during the January trial. The plaintiffs’ team, including former Republican U.S. Solicitor General Theodore Olson, put on weeks of evidence to prove that Prop. 8 violated the rights of same-sex couples.

They presented experts to testify on issues from the history of discrimination against gays and lesbians to the scope of gay and lesbian political clout. Among other things, the plaintiffs sought to debunk the argument that California’s strong domestic partnership laws provide equal status to same-sex couples — Walker agreed that those laws relegated the couples to second-class citizenship.

Defenders of Prop. 8 put just two witnesses on the stand, saying the plaintiffs had failed to prove that voters intended to discriminate and that Prop. 8 is unconstitutional. Prop. 8 defenders tried to introduce evidence to show that gay marriage would undermine the institution of marriage, and that it conflicts with marriage’s central purpose of procreation.

In his ruling, Walker questioned the lack of evidence and called one witness “unreliable,” making it clear that the Prop. 8 defense team did little to prove that the law can be justified. In fact, the judge said only moral disapproval appeared to motivate the law, rejecting the procreation argument.

“The evidence demonstrated beyond serious reckoning that Proposition 8 finds support only in such disapproval,” he wrote. “As such, Proposition 8 is beyond the constitutional reach of the voters or their representatives.”

The legal challenge did not have any impact on the roughly 18,000 same-sex couples married in California before Proposition 8 went into effect.

“The decision grounds its legal conclusions in the factual findings as powerfully as it can,” said Marc Spindelman, an Ohio State University law professor who has followed the issue closely. “But there’s no guarantee that, even decided this way, it will hold against the winds sure to blow as the case is taken up. Far from it.”

Mercury News staff writer Julie Chang contributed to this report. Contact Howard Mintz at 408-286-0236.