The diocese chose the Rt. Rev. Mark Handley Andrus of Birmingham, Ala., on the third ballot to replace the retiring Rev. William Swing. None of the gay candidates received more than a handful of votes.
The packed Grace Cathedral erupted with cheering and applause when the announcement was made.
The vote was closely watched by Episcopalians across the nation and their fellow Anglicans worldwide, who have been struggling to remain unified despite deep differences over gay clergy.
The 77 million-member Anglican Communion, represented in the United States by the Episcopal Church, is still reeling from the 2003 election of the first openly gay Episcopal bishop — V. Gene Robinson of New Hampshire.
Some observers predicted Californians would elect a second gay bishop to force the church to resolve its position on gay clergy. Episcopalians differ over whether the Bible permits ordaining gays but agreed that choosing a second leader in a same-sex relationship would severely damage the global church.
In 2004, Anglican leaders trying to keep the church from splitting asked the U.S. church for a temporary moratorium on electing gay bishops. Those supporting a greater role for gays and lesbians believe it is unfair to ask them to wait, and they question whether any reconciliation can occur when opposing sides have such conflicting views of Scripture.
Andrus emerged as the favorite among clergy delegates in the first ballot and quickly drew the support of lay voters in subsequent ballots. After four hours, he ended up with 72 percent of the clergy vote and about 55 percent of the lay vote.
The openly gay candidates were the Rev. Canon Michael Barlowe of San Francisco, the Very Rev. Robert Taylor of Seattle and the Rev. Bonnie Perry of Chicago. Perry withdrew her candidacy before the final vote. All three have same-sex partners.
Andrus, who has served as bishop suffragan in the Diocese of Alabama since 2001, received his master's of divinity in 1987 from the Virginia Theological Seminary in Alexandria, Va. He is married and has two college-age daughters.
In a statement to California Episcopalians prior to his election, he said he found them "people of passion and energy, commitment, faith and humor. You are able to appreciate yourselves, and be self-critical, both rare qualities."
Nearly 600 delegates gathered for the election.
The Anglican Communion is made up of religious bodies that trace their roots to the Church of England. The Communion is led by the archbishop of Canterbury.
Before he is installed as bishop, Andrus must get approval from the denomination's top legislative body, the General Convention, which is set to meet June 13-21 in Columbus, Ohio. Delegates have a long history of deferring to dioceses' choice of leader.
By KIM CURTIS