Sacramento — After months of furious lobbying, a bill that would help Pacific Gas and Electric Co. deal with the costs of last year’s devastating wildfires — in part by passing some of those costs on to the utility’s customers — won approval from California legislators late Friday.

The bill was sent to Gov. Jerry Brown an hour before the Legislature’s midnight deadline. He is considered likely to sign it, despite bitter complaints from consumer advocates that it represents a bailout of PG&E.

Although the bill, SB901, should ease fears that PG&E’s potential $17 billion liability from the fires could push the company into bankruptcy, it does not give the utility everything it sought.

“Let me make one thing clear, if we don’t provide a debt stabilizing mechanism for the utilities, in this case PG&E, the corporation will certainly face higher borrowing costs which will translate into significantly higher rates or this company may very well face bankruptcy,” said Sen. Bill Dodd, D-Napa, who led the committee that crafted the legislation.

“Without action, ratepayers will be left holding the bag and communities will needlessly suffer,” Dodd said.

The Senate approved the bill 29-4, while the Assembly passed it 45-10.

As fires were still burning across the Wine Country last fall, PG&E began lobbying in Sacramento for a change to state liability rules that hold utility companies liable for damage from wildfires started by their equipment even when they follow all safety laws. The idea won backing from Brown. But legislators abandoned it two weeks ago as too complex and contentious to resolve in the legislative session’s final days.

But the bill approved Friday does offer PG&E, California’s largest utility, significant protections.

It would let PG&E use a type of state-authorized bond to pay off the more than 200 lawsuits filed against the company over the fires. PG&E’s customers would pay off those bonds bit by bit on their monthly bills, provided that regulators with the California Public Utilities Commission determine that the company acted reasonably in maintaining its equipment before the fires. In cases where the commission determines the utility did not act reasonably, PG&E and its shareholders would have to cover the cost.

There would be, however, a limit to how much PG&E would pay. The bill calls for the utilities commission to conduct a bankruptcy stress test, determining how much of a financial blow PG&E could withstand. Any costs beyond that would be passed on to ratepayers.

The San Francisco company estimates that customers would pay an extra $5 per year for every $1 billion in bonds issued.

California fire investigators have blamed PG&E’s equipment for starting at least 16 of the fires that erupted during a fierce windstorm on Oct. 8. And in 11 of those instances, investigators found evidence the company broke state safety laws.

The bill also directs more money to clearing drought-killed trees from the state’s forests and toughens financial penalties against utility companies that violate state rules.

Sen. Hannah-Beth Jackson, D-Santa Barbara, said the legislature’s goal was to ensure the state was doing enough to prevent fires.

“The goal was to protect the victim and the rate payer,” Jackson said. “This measure is a balancing. We also need that energy. If we didn’t need it, boy, I’d be the first to push PG&E off the cliff. But we need their energy and if we push them off the cliff it will cost the ratepayer more.”

Critics considered it a giveaway to a company with a dubious safety history. The fatal 2010 explosion of an old PG&E natural gas pipeline beneath San Bruno led to a $1.6 billion fine from state regulators and a felony conviction from a federal court jury.

State Sen. Jerry Hill, D-San Bruno, noted that the legislative conference committee that crafted SB901 originally set out to aid victims of last year’s fires, make sure PG&E customers didn’t shoulder the costs and help prevent more fires.

“Of those three things, they’ve done one,” Hill said, before Friday’s vote. “On the other two, they’ve gone in the opposite direction of where they said they’d go.”

Hill said PG&E could have done far more to improve the safety of their electrical system and instead focused on profits for their shareholders.

“Shouldn’t we focus on requiring PG&E to improve the safety of their electrical system that they have been neglecting all these years?” Hill said. “Instead, this bill rewards their bad behavior.”

But the bill won support from some of the same people who blocked PG&E’s efforts to change liability laws. The group Up from the Ashes, which represents homeowners and lawyers suing PG&E, described it as a fair compromise.

“The passage of SB 901 tonight by the legislature ensures that victims of last year's deadly utility-caused fires are compensated, future fires are prevented, and utility rates are stabilized without putting PG&E in a position of potential bankruptcy,” said Patrick McCallum, a lobbyist with the group, who lost his own home in the fires.

David R. Baker and Melody Gutierrez are San Francisco Chronicle staff writers. Email: dbaker@sfchronicle.com, mgutierrez@sfchronicle.com Twitter: @DavidBakerSF @MelodyGutierrez