SAN FRANCISCO (AP) — Former state Sen. Mark Leno pulled ahead by the slimmest of margins in the race for San Francisco mayor early Wednesday under the city's unusual voting system, though Board of Supervisors President London Breed maintained her lead in first-place votes.

The race remained too close to call with ballots still being accepted through Friday.

San Francisco uses a ranked-choice voting system that allows voters to select their top-three favorites. The candidates with the least votes are eliminated in rounds until there's a winner; the person with the most first-place votes isn't necessarily that winner.

With about 154,000 votes counted early Wednesday, Breed had 36 percent of first-place votes. Leno had 26 percent of first-place votes and Supervisor Jane Kim had 23 percent.

But a ranked-choice voting analysis posted by the elections office shortly after midnight showed Leno beating Breed by picking up the second-place votes of Kim. The two had banded together and asked supporters to vote for the other as their No. 2 choice on the ballot.

Leno, 66, would make history as the city's first openly gay mayor. He was the first to enter the mayor's race, long before the unexpected death of Mayor Ed Lee in December, which moved up the race.

Leno was not available for comment early Wednesday, but he was upbeat and even went for a ride in a convertible through the city's Castro neighborhood waving to supporters Tuesday night.

"I'm exhilarated for what's coming tonight. We had 300 volunteers contacting every Leno voter, making sure each and every person came out to vote," Leno told the San Francisco Examiner.

Breed, 43, who would become San Francisco's first African-American female mayor, was raised by her grandmother in public housing, graduated from public schools and is touted as a local success story.

"There's still a lot more votes to count. Everyone has cast their ballots and all we can do is wait and see," Breed told supporters earlier Tuesday. "But I feel good inside."

San Francisco is an expensive city with a healthy economy thanks to the tech industry, but homelessness remains an entrenched issue and residents are cranky over filthy streets and traffic gridlock.

Dozens of people lined up outside San Francisco's City Hall on Tuesday, waiting to vote for a new mayor.

Alyssa Sewlal, a 32-year-old Democrat who works for a public policy nonprofit, voted for Breed partly because she has received support from former Republican President Ronald Reagan's secretary of state, George Shultz.

"There's nothing wrong with her getting support from both sides," she said.

All three are Democrats, but Breed is backed by the establishment business community while Leno and Kim are favored by more liberal elements of the party, including tenants and critics of tech companies such as Airbnb and Uber.

In 2010, Jean Quan became the mayor of nearby Oakland when she scored enough second- and third-place votes to beat the candidate with the most first-place votes.

___

Associated Press writer Lorin Eleni Gill contributed to this report.

___

Sign up for "Politics in Focus," a weekly newsletter showcasing the AP's best political reporting from around the country leading up to the midterm elections: http://apne.ws/3Gzcraw

Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.