Three months ago, no one in City Hall would have expected Mark Farrell, then the board’s most fiscally conservative supervisor, to side with its progressives and fund lawyers for all immigrants facing deportation.

But the world of San Francisco politics turned upside down when the progressives on the Board of Supervisors installed Farrell in the mayor’s office last month. His first big move appears to pay them back: This week Farrell teamed up with Assemblyman Phil Ting, D-San Francisco, who will introduce a budget item asking for $7 million annually to pay for universal counsel in Northern California’s immigration court, which is based in San Francisco.

The city’s public defender, Jeff Adachi, supplies most of the immigrant lawyers in that court, and his office would be likely to receive a large share of the state money if it’s approved.

“The rhetoric out of Trump has intensified to a degree we’ve never seen before,” Farrell said in an interview, painting his proposal as a timely act of resistance to President Trump. It came the same week that federal officials arrested more than 150 undocumented immigrants in Northern California cities, including San Francisco.

Yet, if Farrell is taking a noble swipe at federal officials and policy, he’s also made an adroit political move. His proposal would replace legislation by the board’s progressive supervisors to more than triple the size of Adachi’s immigration unit, which is led by the husband of Supervisor Hillary Ronen.

That legislation, which is scheduled to go to the board’s Budget and Finance Committee Thursday, put Farrell in a bind.

As a supervisor he pushed back when Adachi approached the board seeking money outside the normal budget process. The public defender has done that at least four times, and Farrell chastised him for it in 2013. But now Farrell may feel he has to cooperate with the progressives who put him in the city’s top job.

So, they made a deal. Adachi and the progressives had asked for about $5 million: $2 million to add 14 new staffers at the public defenders’ office, and $3 million to fund nonprofits that provide legal services for immigrants. Farrell wants to shunt that burden to the state.

If the state denies his and Ting’s $7 million request, Farrell promised to use the city as a backstop, earmarking enough money for seven public defender staff positions — half of what Adachi wanted — in the two-year budget that he will roll out shortly before leaving office in June. He’ll also chip in the money for the nonprofits.

“I have to say he’s been transparent and forthcoming, and I think he even pushed his budget staff to do this,” said Supervisor Sandra Lee Fewer, who sponsored the progressives’ bill but said that after negotiating with Farrell, she plans to withdraw it and present Farrell’s instead.

Farrell is confident the state will deliver, faced with the public outcry over immigration sweeps and pressure from Ting, chairman of the powerful Assembly budget committee.

“California became a sanctuary state in 2017, and our leaders in Sacramento — in particular our San Francisco delegation of Ting, Assemblyman David Chiu and Sen. Scott Wiener — are strong advocates of that policy,” Farrell said.

Ting noted that the state set aside $45 million last year for legal services for immigrants, at a time when Trump was calling for more deportations. But he couldn’t say for sure whether legislators would cough up another $7 million this year.

That might not matter to Farrell, whose temporary term of office ends in four months.

His proposal is unlikely to quiet criticism from the moderate side of the board that Ronen was helping raise the profile of her husband, Francisco Ugarte. He started the public defender’s immigration unit and still runs it. He would not get a salary increase or promotion if the board approves funding for the office, and City Attorney Dennis Herrera said it doesn’t present a conflict of interest for Ronen.

Even so, some moderates chided Farrell for accommodating people who were once his political foes.

Supervisor Malia Cohen, who chairs the board’s Budget Committee, called the mayor “a known flip-flopper.” She said she is still reviewing the details of his proposal and has not taken a position on it.

That characterization of Farrell angered Ronen.

“Give me a break,” she snapped. “First you criticize progressives for putting a conservative in the mayor’s office, then you criticize that mayor for doing something that everyone agrees is the right thing to do — protecting immigrants.”

Some political experts see the immigration funding package as part of Farrell’s effort to build a legacy quickly.

“This is what he signed up for,” said David Lee, a political science lecturer at San Francisco State University who also runs the nonprofit Chinese American Voters Education Committee.

“As mayor, Farrell has to act on behalf of the entire city,” Lee said. “And voters in San Francisco have overwhelmingly supported immigrant rights and gone against the Trump administration’s policies.”

Fewer and Ronen praised Farrell for crossing partisan lines, and marveled at how much access they now have to the mayor’s office.

“With Ed Lee, I was always dealing with his budget staff,” Fewer said of the former mayor, who died of a heart attack in December. Lee had resisted Adachi’s attempt last year to beef up his immigration unit with 17 staff positions, a mix of lawyers and paralegals. After months of arguing, Lee agreed to add five positions.

Farrell, by contrast, was ready to sit at the table and broker with his new political allies, Fewer said.

“Now we’re able to talk directly to the mayor and make our case,” she said.

“He came up with the idea,” said Ronen. “He’s the one who took the initiative to call his friends in Sacramento.”

But Ronen and Fewer stopped short of embracing Farrell as one of their own. Asked whether they now consider him a progressive, both supervisors flinched. Ronen shook her head.