The candidates include former state Sen. Mark Leno, Acting Mayor London Breed, Supervisor Jane Kim and former Supervisor Angela Alioto. Eighteen others who had requested paperwork to run did not return candidacy papers before Tuesday's deadline.
The race had been scheduled for November 2019 but was moved to June after Mayor Ed Lee, a Democrat, died of a heart attack in December while grocery shopping. The winner will serve out the rest of Lee's term.
The city's next mayor will have to navigate the city's ambivalence about the effect of the booming technology sector on housing, traffic and basic livability. The median home value, for example, is nearly $1.3 million and the median rent is $4,400 - pricing out all but the wealthiest newcomers.
"The driving issue is the city of San Francisco's relationship with the tech industry, and what they want that relationship to be," said Jim Ross, a political consultant who managed Gavin Newsom's winning campaign for mayor in 2003.
He added: "It's the status quo of what we've seen for the last eight years, versus is there going to be a change?"
Lee's legacy of promoting expanded development is a key factor in an election where critics still blame him for ushering in a prosperity that they say has not benefited everyone. For example, he approved a tax break for Twitter and other companies as part of an effort to revitalize part of the downtown area.
Among the candidates are politicians who could become San Francisco's first permanent female African American mayor or first openly gay mayor.
Breed, who is president of the Board of Supervisors, ascended to the role of acting mayor and is seeking the job full-time. Some residents called on the board at its regular meeting Tuesday to appoint an interim "caretaker" mayor who is not interesting in the job permanently.
Other candidates who qualified for the ballot include Leno, a longtime Democratic activist and openly gay politician who wrote legislation to expand gay rights and higher minimum wages; Kim, who was endorsed by Sen. Bernie Sanders in her unsuccessful run for state Senate last year; and Alioto, an anti-discrimination lawyer and daughter of former Mayor Joseph Alioto.
Breed and Leno are the front-runners based on name recognition and access to money, said Jason McDaniel, an associate professor of political science at San Francisco State University.
Both are Democrats, but Leno has positioned himself as the "progressive" who will stand up to big-money interests and focus on the people being pushed out of San Francisco. Leno has the support of Supervisor Aaron Peskin, who is leading the charge to appoint a temporary mayor.
"It's really about whether or not the same old handful of power brokers continues to run San Francisco like a company store, or whether we shake things up and move in a new direction and have a much more independent mayor," he said.
Breed, who is African American and talks of growing up poor in San Francisco public housing, is backed by former Mayor Willie Brown, a kingmaker for decades of city politics and a member of the "moderate" branch of city politics. She said in a tweet announcing her candidacy: "I'm not a partisan. I'm not an ideologue."
San Francisco has gone through the process twice before.
In 2011, Lee was tapped as interim mayor when then-Mayor Gavin Newsom became lieutenant governor. Lee said he wasn't interested in having the job permanently but then ran for two terms. In 1978, Dianne Feinstein became mayor when Mayor George Moscone and board president Harvey Milk were assassinated. She then won two full terms.
Whoever wins in June will fill out the remainder of Lee's term through 2019 and can run for another two four-year terms if they choose.
San Francisco uses a ranked-choice voting system, which is also known as instant runoff. The system allows voters to rank the candidates in order of preference on the ballot, whittling down the candidates until there's a winner so there is no runoff. The mayor's post is nonpartisan.
Qualifying candidates can withdraw until Jan. 30.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.