Several gay and lesbian couples, along with the city of San Francisco and gay rights groups, sued to overturn state laws allowing only marriages between a man and a woman.

With the ruling, California becomes the second state to allow same-sex couples to legally wed. Massachusetts adopted the practice in 2004, and couples don't need to be state residents to wed there.

Vermont, New Jersey, New Hampshire and Connecticut permit civil unions, while California has a domestic-partner registration law. More than a dozen other states give gay couples some legal rights.

Seven other jurisdictions around the world have legalized same-sex marriage: Belgium, Netherlands, Spain, South Africa and the Canadian provinces of British Columbia, Ontario, and Quebec.

San Francisco officials in 2004 allowed same-sex couples in the city to wed, prompting a flood of applicants crowding the city hall clerk's office. The first couple to wed then was 80-year-old Phyllis Lyon and 83-year-old Dorothy Martin, lovers for 50 years.

"We have a right just like anyone else to get married to the person we want to get married to," Lyon said at the time.

One issue before the justices was whether San Francisco's laws carried legal weight when the rest of the state banned same-sex marriages. Gay rights advocates argued the state was violating their civil rights by limiting marriage to opposite-sex couples. The state law in question is the Defense of Marriage Act, Proposition 22.

Oral arguments in the case in March lasted more than three hours, a sign of the political and legal issues at stake. Six cases were consolidated.

Same-sex marriages that were nullified by the law remain nullified, CNN legal analyst Sunny Hostin said.

Groups saying they were promoting a pro-family agenda had vowed to fight a statewide law allowing same-sex marriage.

"The government should promote and encourage strong families," said Glen Lavy of the Alliance Defense Fund. "The voters realize that defining marriage as one man and one woman is important because the government should not, by design, deny a child both a mother and father."

An appeal to the U.S. Supreme Court is likely. The federal high court has never addressed the question of same-sex marriage.