It seemed like a bizarre move for San Francisco’s progressive supervisors: remove a self-made African American woman from City Hall’s top job and replace her with an affluent white man, the goal being to prevent rich white men from shaping city politics.

But behind the vote to replace acting Mayor London Breed with a caretaker was a carefully orchestrated play by the board’s progressives to regain their majority and increase the chances that a candidate of their stripe wins the mayoral election on June 5.

They courted Supervisor Mark Farrell for weeks, weaving a canny but risky plan that could have fallen apart at the last minute.

“I didn’t believe the vote could happen until it happened,” said Supervisor Aaron Peskin, referring to the moment Tuesday night when moderate Supervisor Jeff Sheehy sided with the board’s five progressives to clinch a 6-3 majority for Farrell.

Now Playing:

The drama began with a fierce, unwieldy speech by Supervisor Hillary Ronen, who said Breed was being propped up by tech moguls and real estate billionaires — the same group who bolstered mayors Gavin Newsom and Ed Lee. Recoiling at what she said were “gross politics,” Ronen provided a compelling rationale for her peers to appoint someone new.

“This is definitely a very shrewd power play,” said Jason McDaniel, an associate professor of political science at San Francisco State University. He saw the vote as a way to capitalize on deep divisions between the city’s moderates.

“I saw a faction (of moderates) that seemed to be surprised and unprepared for this,” McDaniel added. “If that’s the case, they should have been thinking about a next-best candidate if they didn’t have support for London Breed.”

Breed was also nominated to be interim mayor until June, but she lost, with five supervisors voting against her and four for her.

The chaotic scene in the board chambers culminated an hour later with a well-staged swearing-in. Farrell took the oath of office accompanied by his wife and three children, who had on dresses and suits for the ceremony. He then read prepared remarks to a throng of reporters.

“This isn’t about politics,” the new interim mayor insisted.

Farrell said in an interview Wednesday that he had talked with all of his colleagues on the board — and scores of others — about his political future since Lee’s unexpected death in December. He was widely seen as a candidate in the 2019 mayor’s race, which abruptly became a six-month sprint when Lee died, forcing Farrell and others to bow out.

“I understood there was a possibility I would be nominated, but nothing was written in stone,” he said. “It could have gone a hundred different ways. But the board entrusted me with this position, and I will take it seriously.”

Reflecting on their decision the next day, several progressive supervisors described Farrell as a business-friendly moderate they could live with for five months. He had crossed ideological lines before, endorsing the liberal David Campos over his more centrist rival, David Chiu, in their 2014 race for state Assembly, which Chiu won.

“Look, I haven’t always been on the same side as Farrell, but I do believe he will fairly and competently run the city,” said Ronen, a former legislative aide to Campos.

Several of her colleagues found themselves playing defense Wednesday, pushing back against allegations of racism and sexism from Breed’s supporters.

“It is unfortunate but understandable that some saw last night’s vote as being racially motivated,” Supervisor Norman Yee said in a statement. “This is not the case.”

Yee had nominated Farrell for interim mayor, saying that Breed undermined the separation of powers in city government by serving simultaneously as acting mayor and board president. Peskin pressed those arguments when he called for the interim mayor vote earlier this month.

But if the supervisors acted on their ideological principles, they also reaped benefits. The progressives cleared a path in the June 5 mayor’s race for Breed’s left-leaning opponents, former state Assemblyman and Sen. Mark Leno and Supervisor Jane Kim, by denying Breed the power of incumbency and the public platform that it brings.

And they got the prospect of an ally in District Two, which Farrell represents. The list of people being contemplated to succeed Farrell, according to people familiar with those conversations, includes Planning Commissioner Rodney Fong, County Clerk Catherine Stefani and former Supervisor Michela Alioto-Pier. All have amicable relationships with the progressive side of the board, and any of them might edge out moderate front-runner Nick Josefowitz in the November election to fill Farrell’s now-vacant board seat. Neither Stefani nor Fong has announced interest in running for the seat, while Alioto-Pier has said she’s strongly considering it.

Farrell has not yet said whom he plans to appoint to serve in District Two until that election, but someone with progressive leanings could switch that faction of the board from a five-person minority to a six-person majority — at least on many issues.

Sheehy, the crucial swing vote, is running a faltering campaign to keep his seat in District Eight — the Castro, Noe Valley and Glen Park — against a challenge from progressive candidate Rafael Mandelman.

Colleagues say he may have had the most to lose, if moderates associated with Breed refuse to donate money or volunteer for his campaign. But by siding with the progressives on this vote, he may have shored up his credentials with some in his district. Sheehy didn’t return calls seeking comment Wednesday.

He may also be rewarded if his colleagues persuade the Democratic County Central Committee, which Campos chairs, not to endorse anyone in the race. Or Sheehy could get a dual endorsement from Leno, who has already stumped for Mandelman.

“That’s a scenario,” Peskin said Wednesday.

If they manage to claim either the executive seat in the June election or legislative branch in November, the progressives could revive such issues as taxes for tech companies, which didn’t get a lot of traction this year with a moderate-majority board. They could also push for higher percentages of affordable housing in new developments.

“This goes beyond maneuvering against an opponent,” McDaniel said. “If they’re actually bringing on Farrell and Sheehy, that shows they’re building a new coalition that could govern the city. And that’s a big deal.”

Rachel Swan is a San Francisco Chronicle staff writer. Email: rswan@sfchronicle.com Twitter: @rachelswan