(05-15) 12:38 PDT SAN FRANCISCO -- Gays and lesbians have a constitutional right to marry in California, the state Supreme Court said today in a historic ruling that could be repudiated by the voters in November.

In a 4-3 decision, the justices said the state's ban on same-sex marriage violates the "fundamental constitutional right to form a family relationship." The ruling is likely to flood county courthouses with applications from couples newly eligible to marry when the decision takes effect in 30 days.

"The California Constitution properly must be interpreted to guarantee this basic civil right to all Californians, whether gay or heterosexual, and to same-sex couples as well as to opposite-sex couples," Chief Justice Ronald George wrote in the majority opinion.

Allowing gay and lesbian couples to marry "will not deprive opposite-sex couples of any rights and will not alter the legal framework of the institution of marriage," George said.

In addition, he said, the current state law, enacted in 1977 and reaffirmed by the voters in 2000, discriminates against same-sex couples on the basis of their sexual orientation - discrimination that the court, for the first time, put in the same legal category as racial or gender bias.

Massachusetts is the only other state whose high court has ruled in favor of same-sex marriage. Federal law denies federal benefits, such as joint income tax filing and Social Security survivors' rights, to same-sex couples who can legally marry in their states, and allows other states to deny recognition to those marriages.

Today's ruling set off a celebration at San Francisco City Hall, where nearly 4,000 same-sex weddings were performed in 2004 before the state high court put a halt to the marriages while challenges to the California law worked their way through the courts. The decision today has no effect on those annulments.

Outside the city clerk's office, three opposite-sex couples were waiting at 10 a.m. for marriage certificates. City officials had prepared for a possible rush on certificates by same-sex couples, but hadn't yet changed the forms that ask couples to fill out the name of the "bride" and "groom."

City officials say they'll probably be unable to marry the same-sex couples for another 30 days when the decision fully goes into effect. But they're making appointments for those weddings now.

"We've waited over 21 years for this day, but today I can finally say I will be able to marry John, the man that I love," Stuart Gaffney, whose marriage to John Lewis was one of those annulled by the court in its 2004 ruling, said at a San Francisco news conference with his lawyers and other plaintiffs. "Today is the happiest and most romantic day of our lives."

The celebration could turn out to be short-lived, however. The court's decision could be overturned in November, when Californians are likely to vote on a state constitutional amendment banning same-sex marriages. Conservative religious organizations have submitted more than 1.1 million signatures on initiative petitions, and officials are working to determine if at least 694,354 of them are valid.

If the measure qualifies for the ballot and voters approve it, it will supersede today's ruling. The initiative does not say whether it would apply retroactively to annul marriages performed before November, an omission that would wind up before the courts.

Liberty Counsel, which represented the group Campaign for California Families before the court in arguing for the state law, denounced the ruling and said it would ask the justices to stay its effect until after the November election.

"The California Supreme Court has defied logic, undermined the will of the people and weakened our future," said Mathew Staver, Liberty Counsel's founder and chief attorney. "This decision will ignite California voters to amend their state Constitution to protect marriage and prevent judges from wrecking marriage."

Glen Lavy of Alliance Defense Fund, which represented other opponents of same-sex marriage, said, "The court's decision clearly demonstrates that marriage is not ultimately safe from tampering by activists and others in government until the voters have amended the Constitution."

But San Francisco City Attorney Dennis Herrera, whose office filed one of the suits challenging the marriage law, said the court acted in the best tradition of an independent judiciary.

"Our democratic system was founded on the notion that the courts should not be swayed by public opinion when it comes to protecting our most cherished rights," Herrera said.

Mayor Gavin Newsom, whose sanctioning of same-sex marriages in 2004 led to today's ruling, said, "It's about human dignity. It's about civil rights. It's about time."

Chief Justice George was joined in the majority by Justices Joyce Kennard, Kathryn Mickle Werdegar and Carlos Moreno. Justices Marvin Baxter, Ming Chin and Carol Corrigan dissented - though Corrigan, writing separately, said she personally believes "Californians should allow our gay and lesbian neighbors to call their unions marriages."

Baxter, writing for himself and Chin, accused the court majority of substituting "by judicial fiat its own social policy views for those expressed by the people."

Both he and Corrigan noted the 2000 ballot initiative in which California voters reaffirmed the state's ban on same-sex marriage.

The court "does not have the right to erase, then recast, the age-old definition of marriage, as virtually all societies have understood it, in order to satisfy its own contemporary notions of equality and justice," Baxter said.

But George, in a 121-page opinion, said California has already recognized, in its laws and public policy, that gays and lesbians are entitled to equal treatment in every legal area except marriage. He also noted that state laws and traditions banned interracial marriage until the California Supreme Court, in 1948, became the first court in the nation to overturn such a law.

"Even the most familiar and generally accepted of social policies and traditions often mask an unfairness and inequality that frequently is not recognized or appreciated by those not directly harmed," the chief justice wrote.

The legal case dates back to February 2004, when Newsom ordered the city clerk to start issuing marriage licenses to couples regardless of their gender, saying he doubted the constitutionality of the state marriage law.

The state's high court ordered a halt a month later, after the nearly 4,000 same-sex weddings had been performed at City Hall. The court annulled the marriages in August 2004, ruling that Newsom lacked authority to defy the state law. But it did not rule on the validity of the law itself and said it would await proceedings in lower courts.

Some of the couples immediately sued in Superior Court and were joined by the city of San Francisco, which said it had a stake in ensuring equality for its residents. The case that ultimately reached the state Supreme Court consolidated four suits, one by the city and three by 23 same-sex couples in San Francisco and Los Angeles.

Superior Court Judge Richard Kramer, ruling in the San Francisco cases, declared the ban on same-sex marriage unconstitutional in March 2005. He said the law violates the "basic human right to marry a person of one's choice," a right declared by California's high court in the 1948 ruling.

Kramer said the law also constituted sex discrimination - prohibited by another groundbreaking California Supreme Court ruling in 1971 - because it is based on the gender of one's partner.

But a state appeals court upheld the law in October 2006, ruling that California was entitled to preserve the historic definition of marriage and that the state's voters and legislators, not the courts, were best equipped "to define marriage in our democratic society."

The appeals court also said California is not discriminating against same-sex couples, citing state laws that give registered domestic partners the same rights as spouses. Those laws provide such rights as child support and custody, joint property ownership, inheritance and hospital visitation, and access to divorce court.

The suits challenging the marriage law relied on the California Constitution, which state courts have long interpreted as being more protective of individual rights than the U.S. Constitution. The initiative that California voters are likely to consider in November would write a ban on same-sex marriage into the state Constitution, a step already taken by voters in half the states.

Gov. Arnold Schwarzenegger has twice vetoed same-sex marriage bills, citing the 2000 ballot measure that reaffirmed California's opposite-sex-only marriage law. That initiative was not a constitutional amendment.

The governor issued a statement today saying, "I respect the court's decision and as governor, I will uphold its ruling." He also reiterated his opposition to the constitutional amendment that is likely to be on the November ballot.

Suits similar to those that went before the California Supreme Court have been filed in other states, but only the Massachusetts Supreme Judicial Court has ruled that the state's constitution gives gay and lesbian couples the right to marry.

Courts in Vermont and New Jersey have found their states' marriage laws discriminatory but left the remedy up to state legislatures, which opted in both cases for civil unions for same-sex couples rather than marriage. A similar ruling by the Hawaii Supreme Court in 1993 was overturned by a ballot initiative.

The California case is In re Marriage Cases, S147999. The ruling is available at www.courtinfo.ca.gov/opinions.

Chronicle staff writers Cecilia M. Vega and Heather Knight contributed to this report. E-mail Bob Egelko at begelko@sfchronicle.com.