Mayor London Breed clearly believes that installing her friend and favored candidate, Suzy Loftus, for an 18-day stint as interim district attorney will pay off politically when voters choose the city’s next top prosecutor Nov. 5.

But it’s a risk that seems to have invigorated the campaign of Chesa Boudin, a deputy public defender and Loftus’ main competitor. There’s a chance those 18 days could be a mere hiccup between the former and new district attorneys.

Loftus, an attorney in the sheriff’s office, will assume the role of interim district attorney on Oct. 18. She and Boudin both reported an uptick in interest in their campaigns over the weekend. The question is: Which one will benefit from last week’s surprising turn of events come election day?

District Attorney George Gascón, who last year announced he wouldn’t seek re-election, abruptly told his staff last Thursday that he was giving two weeks’ notice.

He’s likely to enter the race for Los Angeles district attorney — which has a primary in March and the general election in November 2020 — but doesn’t have to file for that race until Dec. 6. It would have made far more sense for Gascón to quit on Nov. 5, forcing Breed to appoint the winner of that day’s election to serve the rest of his term.

Gascón couldn’t be reached Monday. Alex Bastian, a spokesman in the district attorney’s office (the San Francisco one), said he was unavailable and not at work. You can guess where he was: Los Angeles, apparently in part for a key endorsement meeting scheduled for Tuesday with the LA Fed, the county’s major labor organization. He told Loftus in a phone call Friday he would be back in San Francisco on Wednesday.

Gascón apparently was as surprised as anyone that Breed appointed a short-term replacement and had counted on the mayor accepting his plan for his chief of staff, Christine Soto DeBerry, to assume his responsibilities. Breed and Gascón have long had a contentious relationship — there’s zero chance they orchestrated this move together despite conspiracy theories to the contrary — and the mayor said Monday she didn’t want Gascón’s chief of staff running the office between his departure and election day.

“Crimes are sadly happening in our city every day, and people are not being held accountable,” Breed said. “So there’s no way that I’m going to allow the existing leadership to continue to manage this department.”

Just as Gascón would have been prudent to hold off on any major moves until election day, Breed would have been smart to hold off on an appointment as well. She should have appointed whoever won on Nov. 5 to serve the rest of Gascón’s term, which was set to end in early January.

But that’s not what happened, and the race has taken a major turn, generating far more attention — and questions.

Even Gov. Gavin Newsom weighed in on Monday, saying he, too, was taken aback by Gascón’s resignation, but that he supports Loftus and thinks she’ll be an “outstanding district attorney.”

Of Breed’s quick naming of her as interim D.A., Newsom said, “The only issue is timing, but that’s up to her, and that’s what mayors get to do.”

Loftus said she didn’t hesitate to accept the offer when Breed called her Thursday.

“I’m wired to step in and serve. I said yes immediately,” she said. “To make a political calculation that I’m not going to serve doesn’t put the interests of the city first.”

She said she and Gascón have discussed working together on a cordial handoff.

“I’m already in conversations about how we can make a smooth transition, about how we bring stability to an office that has been in significant disarray, with lawyers leaving every day,” she said.

By many accounts, morale has sunk under Gascón’s leadership as lawyers jump ship and leave the remaining prosecutors with swelling caseloads.

Boudin called the timing of Gascón’s announcement and planned departure “curious,” but he was clearly pleased by the results. His campaign saw a fivefold increase in volunteers and donations over the weekend, he said.

Alicia Garza, co-founder of the Black Lives Matter movement, endorsed him. Former Supervisor John Avalos withdrew his endorsement of Loftus and now supports only Boudin, saying the mayoral appointment smacks of “political opportunism and corruption.” And former state Sen. Mark Leno, who narrowly lost to Breed in the mayoral race last year, came out of political retirement to campaign with Boudin at a Cole Valley rally on Sunday.

“I have kept my powder dry over the past 16 months,” Leno said of the June 2018 race in which Breed squeaked to victory over him. “But when I saw this happen, it just lit my fire. ... To influence the results of an election is never right.”

Boudin said average people on the street have heard about Gascón’s departure and Breed’s appointment of Loftus and don’t like it.

“People were excited about the first open election in 110 years, and they feel like this is interference,” he said. “They want a district attorney who’s accountable to them, not to the mayor.”

Nicole Derse, Loftus’ campaign consultant, said the voters Boudin is talking about were going to vote for him anyway. Loftus, too, saw a big uptick in support over the weekend due to all the media coverage of the appointment, Derse said.

“We welcome voter scrutiny on Suzy’s record and vision for the office because she’s the only candidate who’s ready to turn things around on day one,” Derse said.

Jim Ross, a political consultant not affiliated with either campaign, said Loftus’ appointment could benefit her if she manages to do something impressive and headline-grabbing in her short time on the job. But he said the appointment also comes with a big political drawback.

“It’s clear Suzy Loftus is London Breed’s district attorney,” he said. “I don’t know if being tied to the status quo is necessarily going to be good. I think it could cut both ways.”

Ross is working for an independent expenditure committee in support of another candidate, Leif Dautch, a deputy attorney general for the state. Alameda County prosecutor Nancy Tung is also in the race.

Ross added that the only thing predictable about San Francisco politics is that they’re never predictable.

“Just when you’ve seen it all, something new happens,” he said.

On that we can all agree.

Chronicle staff writers Dominic Fracassa and Alexei Koseff contributed to this report.

San Francisco Chronicle columnist Heather Knight appears Sundays and Tuesdays. Email: hknight@sfchronicle.com Twitter: @hknightsf Instagram: @heatherknightsf