The justices said they would direct state officials "to take all actions necessary to effectuate our ruling," including requiring county marriage clerks to carry out their duties "in a manner consistent with the decision of this court."
The case was set in motion in 2004 when the mayor of San Francisco — the unofficial capital of gay America — threw City Hall open to gay couples to get married in a calculated challenge to California law. Four-thousand gay couples wed before the Supreme Court put a halt to the practice after a month.
Two dozen gay couples then sued, along with the city and gay rights organizations.
Thursday's ruling could alter the dynamics of the presidential race and state and congressional contests in California and beyond by causing a backlash among conservatives and drawing them to the polls in large numbers.
A spokesman for Republican John McCain, who opposes gay marriage, said the Arizona senator "doesn't believe judges should be making these decisions." The campaigns of Barack Obama and Hillary Rodham Clinton said they believe that the issue of marriage should be left to the states.
Ten states now offer some form of legal recognition to same-sex couples — in most cases, domestic partnerships or civil unions. In the past few years, the courts in New York, New Jersey and Washington state have refused to allow gay marriage.
Outside the San Francisco courthouse, gay marriage supporters cried and cheered as news spread of the decision. Jeanie Rizzo, one of the plaintiffs, called Pali Cooper, her partner of 19 years, via cell phone and asked, "Pali, will you marry me?"
Shannon Minter of the National Center for Lesbian Rights said same-sex marriage advocates could not have hoped for a more favorable ruling by the Republican-dominated court. "It's a total victory," Minter said.
California already offers same-sex couples who register as domestic partners many of the legal rights and responsibilities afforded to married couples, including the right to divorce and to sue for child support.