State Senator Scott Wiener and Supervisor Connie Chan, the two Democrats running to succeed former Speaker Nancy Pelosi, clashed over how to regulate artificial intelligence in their first televised debate on Thursday night, days before ballots go out to San Francisco voters.

The candidates found common ground on one point: A.I. companies should not be left to police themselves, a pushback against a recent suggestion from President Trump. From there they disagreed on nearly everything, each arguing to be the more trustworthy candidate on A.I. safety.

Mr. Wiener pointed to his role in passing the nation’s first A.I. safety law in 2025, a yearslong negotiation that produced a compromise with Gov. Gavin Newsom, who had vetoed a tougher Wiener bill the year before but has since adopted many of its tenets. Mr. Wiener said the law had been “copied and pasted” by several other states, and mocked Ms. Chan’s lack of a record on the industry. “It’s very easy, when you’ve never lifted a finger for AI safety regulation, to armchair quarterback it,” he said.

Ms. Chan countered with a 2024 law banning landlords from using A.I. to set rents, written by her former boss and mentor, then-Supervisor Aaron Peskin. As of August it had produced no enforcement. She repeatedly described Mr. Wiener as beholden to wealthy tech interests, making broad, unsubstantiated allegations that his campaign was “bankrolled” by the companies he regulates, and called his law, Senate Bill 53, “watered-down.” “That’s politics,” Mr. Wiener replied. “I’m proud of the work that we’ve done, and I will take that work to Congress.”

The race is the first real choice San Franciscans have had for the seat in more than 40 years. Mr. Wiener won the June top-two primary with more than 40 percent of the vote and holds the endorsement of The San Francisco Chronicle; Ms. Chan, who represents the Richmond district on the city’s west side, took just under 30 percent, edging the progressive Saikat Chakrabarti, and has Ms. Pelosi’s endorsement and the support of her political operation. The roughly 30 percent of primary voters who chose someone else could decide the outcome on Nov. 3.

Asked how she would regulate A.I., Ms. Chan offered no specifics but called for a moratorium on data centers and restrictions on developing a “superintelligence” that exceeds human intelligence. She said workers threatened by the technology must be part of any talks, recalling nurses whose required A.I. notetakers tracked their emotional relatability and vocal intonation with patients. “That is just simply surveillance of an employee and a worker, not providing better patient care,” she said. “Unions need to be at the table to regulate this technology.”

Midway through the debate, Mr. Wiener apologized onstage for what he called his campaign’s “terrible mistake” of releasing an A.I. chatbot that mimicked Ms. Chan and drew attention to her record of opposing housing construction as supervisor. “Supervisor, I want to directly apologize to you for that chatbot,” he said. “It was a terrible mistake, which is why we took it down and why I apologize. I take full responsibility for that.”

Housing remained a sore point. A moderator, Scott Shafer of KQED, noted that since Ms. Chan took office in 2021, fewer new homes have been approved in her district than any other in the city, and asked how she would explain that to voters. She pointed to construction citywide and her support for rental subsidies, saying “we need to build housing and we need to build housing that people can afford,” without directly answering.

The candidates agreed on plenty as well. Both support universal health care coverage. Both called the humanitarian crisis in Gaza a “genocide,” though critics have questioned whether Mr. Wiener’s adoption of the word reflected conviction or pressure. Both said they would oppose sending American troops to defend Taiwan if China attacked. And each claimed the closer tie to organized labor: Ms. Chan holds endorsements from the California Labor Federation and SEIU California, while Mr. Wiener cited his backing from the activist Dolores Huerta and the labor standards written into his housing bills. Ms. Chan, though, never mentioned Ms. Pelosi’s endorsement during the debate.

Thursday’s meeting was the first of two debates scheduled before the Nov. 3 election.