Marcio Jose Sanchez / AP

Updated on June 12 at 7:27 p.m. ET

A week has passed since San Franciscans went to the polls to choose their next mayor, and the only thing the city knows for sure is that its ranked-choice voting system has produced the closest mayoral election in decades.

On election night, it looked like former state Senator Mark Leno would prevail over London Breed, president of the city’s Board of Supervisors, to finish the term of Mayor Ed Lee, whose sudden death in December created the need for the June 5 special election. Leno, who is bidding to become the first openly gay mayor of the famously gay-friendly city, held a lead of 1,146 votes after the first batch of votes were tallied.

But as city officials have spent the last week counting mailed-in ballots received on or after Election Day, Leno’s lead dissipated and then vanished entirely. Breed surpassed him over the weekend, and in the latest tally published by the Department of Elections on Tuesday afternoon, she was ahead by 1,861 votes.

Yet with thousands of mail and provisional ballots still uncounted, the race for San Francisco’s top job remains officially too close to call.

“We certainly can’t say it’s a done deal,” Breed’s campaign chairman, P.J. Johnston, told me by phone on Monday evening. Johnston said the campaign was “cautiously optimistic” about the outcome given that Breed had gained in the balloting each day since the election.

“Cautious optimism” was also the watchword of the Leno campaign, though perhaps with a greater emphasis on caution than optimism. “We are waiting until the remaining votes are counted,” spokeswoman Zoë Kleinfeld said. “With a historically high turnout, we’re going to honor every single voter.”

The last San Francisco mayor’s race to be nearly this competitive was in 1995, when Willie Brown led in the initial election by barely 2,000 votes before winning more easily in a runoff. “It is the tightest I’ve ever seen,” said Johnston, a veteran Democratic strategist.

John Arntz, director of the San Francisco Department of Elections, told me that because of state rules for canvassing ballots, the results of the mayor’s race could take until the end of June to be certified. But Kleinfeld told me the outcome should become clear “in the next few days” and that Leno would make a statement then. Unless there’s another dramatic shift in the tally, that is likely to be a concession.

The winner won’t take office until July at the earliest and will serve until the end of 2019, when Lee’s second term would have concluded.

If she wins, Breed, 43, would become the first African American woman to lead San Francisco and the only woman mayor in any of the nation’s 15 most populous cities. As president of San Francisco’s version of a city council, she became acting mayor after Lee’s death from a heart attack late last year. But in a controversial move, Breed’s colleagues on the Board of Supervisors would not allow her to continue in the post while she ran for mayor, believing that would give her the unfair advantage of incumbency in a race that included another supervisor, Jane Kim. The Board in January installed Mark Farrell as interim mayor, angering Breed supporters who saw a racial motivation in the decision to replace an African American woman with a white man. Breed, Leno, Kim, and Farrell are all Democrats.

Though progressive on social and national economic issues, Breed was seen as more moderate locally than either Leno or Kim, her two closest rivals, in a campaign that was dominated by debates over affordable housing and San Francisco’s homelessness crisis. Her opponents criticized the support she received from Ron Conway, a billionaire tech investor who gave her his public blessing at Lee’s funeral and then funded super PAC ads to boost her candidacy.

In the final weeks, the race turned not on a policy fight but on a tactical choice by Leno and Kim to forge an alliance under San Francisco’s ranked-choice voting system. The two rivals held a joint press event and filmed an ad urging their respective supporters to make the other candidate their second choice on the ballot. Under the ranked-preference system, voters can list up to three candidates. If no one receives a majority on the first ballot, the contender with the fewest votes is eliminated, and the second-choice votes are added to the remaining candidates’ totals. The process continues until someone gets a majority. More than three out of four Kim voters followed her advice and put Leno as their second choice.

San Francisco has been using ranked-choice voting in municipal elections since 2003, but this is the first mayor’s race where two prominent contenders have aligned so explicitly. Had the city been using a traditional voting system, Breed would have won handily. She led the first-choice ballot by nearly 12 points over Leno and 13 over Kim.

Leno and Kim’s decision to align drew criticism from the San Francisco Chronicle, which said the candidates were trying to game the ranked-choice system. Johnston called it “a last-ditch effort to salvage the campaign.”

It nearly worked.

“Hell, it still might work,” he said, citing the lingering uncertainty.

Breed and her campaign have resisted the temptation to criticize the ranked-choice system, despite the headache it has caused for her bid. Supporters of the reform say it succeeded in reducing negativity in the mayor’s race and juicing turnout, which is likely to end up close to or over 50 percent—exceeding expectations for a non-November election.

Ranked-choice ballots are tabulated automatically, so the system is not what is causing the lengthy count, Arntz said. The blame for that belongs to San Francisco’s four-card ballot, which is filled with multi-candidate primary races and referenda questions. “A four-card ballot just takes four times longer to process than a one-card ballot,” he said.

But Johnston argued that “voter confusion and voter error” associated with ranked-choice voting had also delayed the count. “I don’t think it’s been entirely embraced and understood by the electorate,” he said.

Johnston noted ruefully that supporters of the system have marketed it both in San Francisco and elsewhere as the equivalent of an “instant runoff.”

“It’s certainly turned out to be anything but instant,” he lamented.