SAN FRANCISCO — Marriage remains illegalfor same-sex couples in California, save for about 18,000 of them who slipped under the wire last year.

In a ruling that gay-rights leaders called a “terrible blow,” a “bitter pill to swallow” and a step “backward,” the California Supreme Court on Tuesday ruled 6-1 in three consolidated cases to uphold Proposition 8, the November ballot measure that restricted marriage to heterosexual couples.