Beverage companies spent at least $7 million to get an initiative on the ballot this November that would have prevented local communities from raising taxes without approval from two-thirds of voters or an elected body, rather than a simple majority. Such a change would have made it much more difficult for localities to pay for police, fire, transit and other public services.

According to several state senators, the industry then went to lawmakers in Sacramento with a proposal: Pass a bill banning soda and food taxes, and the industry would drop its November ballot initiative.

“They sent us a ransom note that they will drop this horrible ballot measure if we put a 12-year moratorium on local soda taxes,” said Mr. Wiener, who has long supported soda taxes and voted against the bill that now bars them. “It’s a classic case of picking your poison. The soda industry has gone completely rogue.”

Several top lawmakers said they opposed the measure banning soft drink taxes, known as Senate Bill 872, b ut many felt obliged to support it because they were so worried about the effects of the broader ballot initiative.

Nancy Skinner, a state senator who represents Richmond, Calif., as well as three cities that passed soda taxes in 2016, voted against the measure but said she recognized that her colleagues who supported it were in a bind. The law will not overturn soda taxes enacted before 2018, but it will prevent any new ones, including a soda tax on the ballot later this year in Richmond. “It is totally wrong to deny the residents of Richmond a vote,” she said.

Gov. Jerry Brown avoided taking a position on the bill until Thursday but has now signed it into law. Critics of the bill pointed to a photo that shows him posing with executives from Coca-Cola, PepsiCo and the American Beverage Association at a recent private dinner at the governor’s mansion. The governor’s spokesman said the meeting was unrelated to the soda tax measure .

The push for the pre-emption law began to materialize this year when an industry-financed group, the California Business Roundtable, started collecting signatures for the ballot initiative making local tax increases harder. The American Beverage Association California PAC contributed heavily to the effort, raising $6 million from Coke and Pepsi, $1 million from Dr Pepper Snapple and $100,000 from Red Bull.