It seems like San Francisco — the center of the nation’s tech boom and the strong economy and tax revenues that come with it — went overnight from being flush to having serious financial constraints.

The combination of a ballot measure to increase the sales tax that failed, threatened federal cuts from President-elect Donald Trump and a projected $5 billion pension shortfall means City Hall officials are now considering actions that would have seemed unthinkable just three weeks ago.

Among them: redirecting new revenue generated by the just-passed soda tax from health programs to homeless services, ending the Twitter tax break that was designed to draw tech companies to the city, annulling a voter-approved charter amendment to pay for street tree maintenance and not spending the money to make City College free.

“The city is in a strong financial position, and the mayor is committed to remaining disciplined when it comes to the budget,” said Deirdre Hussey, Mayor Ed Lee’s spokeswoman. “However, the city’s revenue growth is slowing and pension costs have risen in recent years faster than projected. ... These things combined make it essential for policy makers to rebalance the budget.”

San Francisco’s current annual budget is $9.6 billion, up from $6.4 billion in 2010. It’s bigger than the budgets of 13 states, a reflection in part of the city’s strong economy. The two-year budget passed in July has no cuts to city services, and departments large and small got more money. It also funds a 4 percent expansion in the city’s workforce, from just under 30,000 to 30,750 workers.

Three main factors have led to the rapid reassessment of the city’s finances.

•The loss of Proposition K, a proposed three-quarter-cent sales tax increase on the November ballot that would have generated around $100 million annually for transportation projects plus another $50 million for homeless services. The supervisors and mayor passed the budget on the assumption that Prop. K would pass.

•Trump’s unexpected victory. The president-elect has vowed to cut all federal funding to any city with a sanctuary policy of not aiding immigration agents. San Francisco receives about about $1 billion each year from the federal government. While the loss of all that money is unlikely — most cuts would require congressional action — city officials are nevertheless preparing for the worst.

•A looming $5 billion pension shortfall, driven by pension increases, longer life expectancy and lower-than-expected returns on stock market investments. Also, a 2011 voter-approved measure that would have rolled back pension increases for thousands of city employees and retirees was struck down by a state court of appeal in 2015. And in September, the city controller sued the city’s retirement board for approving pension increases, saying the action violated the 2011 ballot measure and would cost the city more than $200 million over the next five years.

The loss of Prop. K is the most immediate blow to the city’s finances.

Jeff Kositsky, director of the new Department of Homelessness and Supportive Housing, has projected to other city officials that without that money the department won’t be able to open three new planned Navigation Centers, special shelters with wraparound services and intensive case management. It would also have to cut back on housing subsidies, new leases for buildings to house the formerly homeless and a planned expansion of the Homeless Outreach Team, which connects people living on the street with services and temporary beds.

Lee doesn’t want those things to happen — dealing with the city’s homeless crisis is among his top priorities. That means the money has to be found elsewhere.

Among the options being considered is using revenue from the new soda tax, which will generate an estimated $7.5 million next year and $15 million in 2018-19. Backers of the soda tax don’t want that to happen — they want the money used for health-related purposes, as they promised voters it would be.

For the revenue to be guaranteed for health purposes, the proponents would have had to structure the measure differently and gotten the support of two-thirds of voters. By not earmarking the funds, the measure needed only a simple majority to pass. It passed with 62 percent of the vote.

Another idea is to use revenue generated from the real estate transfer tax — also approved by voters in November — on properties selling for at least $5 million. In July, the Board of Supervisors passed a nonbinding resolution agreeing to pay for free City College with transfer tax revenue, an estimated $45 million annually.

The question now is whether the mayor and supervisors will decide that money is better spent elsewhere. On Wednesday, the Board of Supervisors Budget Committee will consider legislation to authorize $9 million in new spending to make City College free.

A third option is for the mayor to suspend Prop. E, the November ballot measure that mandates a $19 million set-aside so the city instead of property owners can maintain street trees. However, the measure also has a provision that the mayor can suspend Prop. E before Jan. 1, 2017, after taking into account the city’s finances.

Unsurprisingly, the respective proponents of the soda tax, free City College and street tree maintenance don’t want to see money for their priorities siphoned off.

“The overwhelming majority of the Board of Supervisors have already made their commitment to funding free City College given the passage of new revenue and ... I expect we will be funding a free City College in August 2017,” said Supervisor Jane Kim, who championed the idea.

Supervisor Scott Wiener, who supported both the soda tax and street tree measure, said it wouldn’t be appropriate to take funds from either initiative to instead pay for the lost homeless services.

Meanwhile, Supervisor Aaron Peskin said he planned to introduce legislation to rescind the Twitter tax break, the program that gives a tax break to companies that move into buildings in Mid-Market.

But rescinding the tax break won’t generate huge sums of money. Currently, it costs the city around $34 million annually in lost payroll taxes. Even if it is rescinded, companies already receiving the tax break would continue to do so until the legislation’s original 2018 expiration date.

Despite all this, the city is in financially good shape. Eight percent of its general fund dollars — around $67 million — are in reserves. And on Monday, the chief financial officer is expected to release a report that shows the city ended last year with more money than it expected, including $12 million for the General Fund. However, that is one-time money and couldn’t be counted on year over year.

Gabriel Metcalf, president of SPUR, the urban-planning think tank, said the biggest threat to city finances is if President-elect Trump and Republicans in Congress follow through on their threat to deny federal funding to San Francisco and other sanctuary cities.

If that happens, he said, city officials and San Francisco residents will have to rethink their penchant for mandatory budget set-asides, on everything from tree maintenance to maintaining parks and caring for the elderly. One in five new tax dollars goes to mandated set-asides.

“The fact is that we have locked up a very large share of our city budget with set-asides,” Metcalf said. “If the worst-case scenarios of federal retaliation and budget cuts come to pass, San Francisco is going to have to rethink our budget structure.”

Emily Green is a San Francisco Chronicle staff writer. Email: egreen@sfchronicle.com Twitter: @emilytgreen