The outcome of the still-undecided race for state attorney general could also affect the fate of Proposition 8, California’s ban on same-sex marriage.

San Francisco District Attorney Kamala Harris, who now trails Republican Steve Cooley in their lead-changing race as thousands of late ballots are being counted, opposed Prop. 8 and backed outgoing AG Jerry Brown’s decision not to defend it in court.

Cooley, the Los Angeles County district attorney, said during the campaign that, if elected, he was prepared to give the ballot measure the defense it never got from the state.

But Cooley probably wouldn’t have a chance to do that right away even if he won the election. The Ninth U.S. Circuit Court of Appeals in San Francisco is scheduled to hear arguments Dec. 6 in an appeal by Prop. 8’s sponsors from a federal judge’s ruling that declared the measure unconstitutional. The state’s deadline for appealing that ruling has expired, and if Cooley takes office in January, the court’s not likely to let him enter the case as a party.

That would leave Prop. 8’s sponsors, who call themselves Protect Marriage, and possibly the supervisors of Imperial County as the only ones defending the November 2008 initiative. And there’s a chance that the court will decide they lack standing — the right to represent the interests of the state in defending its laws. A 1997 U.S. Supreme Court ruling questioned whether the private, unelected backers of a ballot measure have standing to represent the state or its voters, and Chief U.S. District Judge Vaughn Walker in San Francisco said in his latest ruling that he doubts Prop. 8’s proponents are legally entitled to appeal.

If the appeals court and the Supreme Court deny standing, they could toss out Prop. 8 without deciding whether it violates the constitutional rights of gays and lesbians to choose a marital partner, as Walker concluded. But that’s where the plot thickens.

According to UC Irvine law Dean Erwin Chemerinsky, a liberal scholar who opposes Prop. 8, Cooley — if elected — could then go back to the trial court and move to reopen the case.

The procedure is called Rule 60(b) and it’s designed for cases in which a ruling was the product of clerical errors, other mistakes or fraud, or when newly discovered evidence casts doubt on the verdict. But Chemerinsky said a new attorney general could argue that he has evidence for the validity of Prop. 8 that wasn’t presented at trial.

The motion wouldn’t go to Walker, who’s retiring from the bench in February, but to another Bay Area federal judge selected by random draw. And if that judge decided to reopen the case, we could be back at square one.

“I’m not saying how it would turn out,” Chemerinsky told reporters at a briefing a few weeks ago. But it’s another reason to keep an eye on the vote count in the AG’s race.

Bob Egelko covers the law and politics for The Chronicle. E-mail him at begelko@sfchronicle.com.