SACRAMENTO — After months of dire warnings and a week of round-the-clock arm-twisting, Gov. Arnold Schwarzenegger today will finally sign a $41 billion budget package of steep tax increases and spending cuts. That simple act will cap a drawn-out drama to keep the state from going broke.

There is something in the package sure to offend nearly everyone: fed-up voters, tax-averse conservatives, labor unions, environmentalists, educators and local officials worried about how to keep the fraying social safety net from snapping.

The deal could also end the political careers of the handful of Republican legislators who joined fractious Democrats to vote "yea" as the sun rose Thursday.

And even as Schwarzenegger on Thursday afternoon thanked the Legislature for its "difficult but courageous" vote, he acknowledged that much remained to be done. "Our work is not over," he said, referring to a soon-to-be launched campaign to pass ballot measures that were tied to the budget vote.

Those measures to reform the state's political system, demanded by GOP Sen. Abel Maldonado as a condition for his deciding vote, ended a three-month impasse over how to patch a projected $40 billion deficit and build a $1 billion reserve.

The standoff halted funding for public works projects across California, delayed refunds for millions of taxpayers, forced unpaid furloughs for thousands of state workers and caused the state's credit rating to be downgraded, rendering it virtually unable to borrow money.

The breakthrough, after more than five full days of sometimes round-the-clock negotiations in the Legislature, came around 1 a.m. Thursday, when top Senate Democrats agreed to meet Maldonado's demands. Among them: an overhaul of the state's electoral system to do away with partisan primaries and a refusal to raise lawmakers' pay when the state is running a deficit. Both questions will be put before voters in June 2010.

Maldonado, a moderate Republican whose district includes parts of Silicon Valley, also forced through a last-minute agreement to trim the package's tax increases to $12.8 billion by eliminating a 12-cents-per-gallon excise on gasoline; the difference will be made up with California's share of federal economic stimulus money.

One assemblyman called the deal "blackmail, extortion, and skulduggery." Another labeled it "political ransom." Senate President Pro Tem Darrell Steinberg, D-Sacramento — who on Tuesday had ordered that legislators be locked inside the Capitol building until they forged a deal — at one point ordered recalcitrant Democrats into his office one by one to cajole their cooperation.

Even so, when the Senate resumed session around 3:40 a.m., four Democrats initially refused to vote for Maldonado's open-primary proposal, which advocates say could break partisan deadlock by giving more power to moderate voices but which both parties fear could endanger safe seats. The idea has been shot down twice in California in the past decade: once by the U.S. Supreme Court and, more recently, in 2004, when voters rejected Prop. 62.

Sen. Gloria Romero, D-East Los Angeles, was near tears as she called her party's capitulation to Maldonado "a disgusting process." Yet she, like the other holdouts, changed her vote to yes, and the Senate approved the open-primary measure just before 5 a.m.

The state Assembly passed the measure at 6:30 a.m. Assembly GOP leader Mike Villines, of Fresno, Roger Niello of Sacramento and Anthony Adams of Hesperia provided the three Republican votes to put the budget over the two-thirds threshold needed to raise taxes.

Mere hours after the vote, Adams was targeted by a conservative group that vowed to mount a recall campaign against him.

Yet bleary eyed legislators traded exhausted smiles and hugs when the more than two dozen pieces of legislation in the budget package had finally passed, and the state's historic standoff came to an end.

Tax refunds and billions in other payments that had been held up because the state could not cover the checks are now on track to be released in late February or early March, according to state Controller John Chiang.

The budget is intended to close a projected $42 billion deficit through mid-2010. It includes a 1-cent sales tax hike, increased income taxes, deep cuts to education and social services and fast-tracked environmental review for some state construction projects. Also tucked in was a controversial tax break that benefits the high-tech and biotech industries — sure to be a boon for Silicon Valley companies.

Besides the ballot measures agreed to at Maldonado's behest, parts of the plan depend on other measures voters will be asked to approve in a special election in May. One proposition would seek to expand the state lottery and borrow $5 billion against the increased revenues. Another would impose a cap on state spending of roughly 4 percent to 6 percent annually.

If voters approve the spending limit, most of the taxes would last for four years. If it fails, the taxes would expire after two years.

The overall budget deal involved major trade-offs for both parties that they would never have agreed to absent the state's financial crisis. "I don't think anybody's happy with this," said Sen. Denise Moreno Ducheny, D-San Diego, "other than we get to go home and sleep."

Reach Edwin Garcia at 916-441-4651.