Interim District Attorney Suzy Loftus led Chesa Boudin by a scant 240 votes early Wednesday morning in the tight race to become San Francisco’s top prosecutor in an election that offered dueling visions for the city’s criminal justice system.

Boudin, an attorney in the public defender’s office, was leading Loftus in first-place votes, 32.9% to 30.9%. But when the city’s ranked-choice voting was tabulated, Loftus garnered more second- and third-place votes and pulled ahead, 50.13% to 49.87%.

By Wednesday morning 115,183 ballots had been processed and all of the city’s precincts had reported. The city Department of Elections said it is still processing 70,000 ballots, including 57,000 vote-by-mail ballots and 13,000 provisional ballots. The office will release the next round of results at 4 p.m.

The other candidates were trailing by significant margins. Nancy Tung, a prosecutor in the Alameda County district attorney’s office who pledged to go after open-air drug dealing and other crimes that have plagued neighborhoods like the Tenderloin, was in third place with 20.8% of first-choice votes.

Leif Dautch, a prosecutor in the state attorney general’s office, was trailing at 15.4%.

Under the ranked-choice system, voters select their top three candidates. If no candidate receives a majority of first-place votes, the candidate with the fewest votes is eliminated and his or her votes are redistributed to supporters’ second choices. That process continues until a candidate goes over 50%.

Leading into Tuesday’s election, Boudin amassed a groundswell of support, both locally and nationally, for his plan to make progressive reforms favoring rehabilitation over incarceration.

Loftus ran a campaign that focused on property crime and street-level problems — and suggested Boudin would be too permissive.

The race, the first open election for San Francisco district attorney in more than a century, intensified last month when sitting District Attorney George Gascón quit early to run, in next year’s election, for the same job in Los Angeles County.

Mayor London Breed tapped Loftus, 45, the candidate she had endorsed, to serve as interim district attorney. The move prompted accusations that Breed was unfairly granting her preferred candidate the benefit of incumbency.

A city’s district attorney sets many of the priorities for law enforcement, and Breed has been under pressure to deal with frustrating issues such as rampant downtown drug-dealing and car break-ins.

Boudin, 39, campaigned to make San Francisco the latest city to elect a progressive district attorney, amid a national movement to reckon with racial disparities in the criminal justice system and hold police accountable for brutality.

If elected, Boudin wouldn’t be the first progressive to hold the seat in San Francisco. Gascón was widely seen as one of the most progressive district attorneys in the country. Terence Hallinan, a former defense attorney like Boudin, ran the office for two terms beginning in 1996.

Before running, Boudin worked to overhaul the state’s cash bail system, helped develop an immigration unit in the public defender’s office, and created the office’s pretrial release unit, which put attorneys in city jails to review defendants’ cases before arraignment.

Boudin used his life story to drive home his vision of reform. His left-wing radical parents, members of the Weather Underground, were incarcerated when he was an infant for taking part in an armored car robbery in upstate New York that led to the death of two police officers and a security guard.

Boudin was raised in Chicago by Weather Underground leaders Bill Ayers and Bernardine Dohrn. He went on to study law at Yale, earn a Rhodes Scholarship and work for Venezuela’s now-deceased socialist President Hugo Chávez before coming to San Francisco.

He pledged to be tougher on police shootings and was the only candidate who said he would have filed charges against officers in the 2015 killing of Mario Woods in the Bayview.

Loftus, a San Francisco native, began her career as a city prosecutor under then-District Attorney Kamala Harris and later worked in the state attorney general’s office.

She was president of the city Police Commission as it dealt with a string of controversial killings by police — including that of Woods — that led to the resignation of Police Chief Greg Suhr in 2016.

Loftus had worked with Suhr to change the department’s use-of-force policy to emphasize de-escalation, and she helped bring in the U.S. Department of Justice to oversee reforms that continue today. Use-of-force incidents have declined 43% since the beginning of 2016, and there hasn’t been a police shooting since June 2018.

After Loftus resigned as commission president in early 2017, she became assistant chief legal counsel at the San Francisco Sheriff’s Department.

In the last months of the race, Loftus spoke less about her background as a reformer, instead emphasizing her law-and-order credentials. She pledged to tackle the city’s unprecedented spike in property crime, specifically auto burglaries, which crested in 2017 at 31,000 reported cases.

Last week, Loftus called a news conference to announce the creation of an auto burglary strike force. She stood with the police chief and sheriff, and though the plan was light on specifics, the optics were clear: She would work closely with law enforcement and make property crime a priority.

Loftus also pulled the plug on Gascón’s program to divert first-time drunken driving cases out of court, a program similar to one Boudin advocated during the race.

Money poured into the race in the final weeks, with the biggest contributions made to independent expenditure committees.

The union representing rank-and-file San Francisco police officers spent more than $600,000 to run attack ads against Boudin. Meanwhile, a progressive group, Youth and Families Taking Power Supporting Chesa Boudin for SF District Attorney, spent more than $188,000 to support him.

Evan Sernoffsky is a San Francisco Chronicle staff writer. Email: esernoffsky@sfchronicle.com Twitter: @EvanSernoffsky