Gov. Mark Dayton and the Republican-controlled Legislature finalized a deal Tuesday on a two-year, $46 billion budget that will cut taxes, increase education and transportation spending and borrow nearly $1 billion for a package of public works projects around Minnesota.

Although the bills had not passed as of late Tuesday, Dayton and legislative leaders have a signed agreement that gives each side some but not all of what they wanted.

The deal mixing tax cuts and spending increases reflects the divided government that Minnesotans sent to St. Paul by electing a GOP-controlled House and Senate in 2016 and twice electing DFLer Dayton.

House Speaker Kurt Daudt, R-Crown, said the agreement was a good one for Republican priorities.

“About two-thirds of the resources are going to be spent on tax relief for Minnesotans and on roads and bridges,” he said, referring to $650 million in tax cuts and $300 million in new transportation funding out of a projected budget surplus of $1.5 billion. “I think those are exactly the kinds of priorities that Minnesotans sent Republicans here to the Legislature to accomplish,” he said.

But Dayton also scored victories. Republicans agreed to an increase of $483 million in education funding during the next two years, including $50 million to expand prekindergarten, which is a key Dayton priority.

Dayton also managed to scale back significant cuts to health and human services that Republicans passed earlier in the session before he vetoed them.

The public works package — approaching $1 billion to build and maintain projects around the state — has also been a Dayton priority for several years.

His clean water initiative that requires landowners to plant buffer strips around public waterways to protect them from pollution had been under assault but survived, including funding to help farmers comply with the new law.

The compromises followed a deal on criminal justice policy Monday, when Dayton agreed to language barring immigrants in the country illegally from receiving driver’s licenses, while GOP lawmakers withdrew a provision that would institute harsh new penalties on protesters who block freeways.

The session is not ending without disagreement, however.

Republicans were set to pass a bill known as pre-emption that would restrict cities from passing their own minimum wage, sick pay and other labor standards — a key priority of the GOP’s business allies.

As part of the agreement with Dayton, Republicans kept the measure out of their budget bills; Dayton has said he would veto it.

But to make the veto more painful, Republicans loaded the bill with other provisions that are important DFL priorities, including a measure to punish wage theft and another to provide paid sick and family leave for state workers, who already have the benefit but would lose it if Dayton does not sign the bill.

“It is unconscionable that Republican legislators would pit the earned financial security of hardworking state employees and retirees against the rights of local officials to make the decisions for which they were elected by their citizens,” Dayton said in a statement Tuesday night, adding that he would honor his commitment and veto the bill anyway.

Lawmakers worked through the night Tuesday and were expected to be debating and voting on a series of budget provisions early Wednesday.

The tax bill totaled $650 million in reductions spread among Social Security recipients, Minnesotans with student loans, parents with child care costs, business property owners, farmers and a raft of other interest groups. It also benefits tobacco users by cutting the state tax on cigars and repealing an automatic yearly increase in the state’s cigarette tax. Absent from the bill was a Republican plan to grant tax breaks in return for donations to private school scholarship funds — which Dayton had criticized as a voucher program.

To offset significant cuts to health and human services, Dayton and legislators agreed to dip into the Health Care Access Fund — funded by a 2 percent tax on medical providers that is scheduled to disappear in 2020.

This raised concerns among some fiscally conservative Republicans. “If we keep spending that money, it puts the Legislature in a difficult spot” once the tax goes away, said Rep. Nick Zerwas, R-Elk River. That’s because the Legislature would then be forced to make deep cuts once the tax disappears.

The budget for health and human service programs is 28 percent of the state’s general fund, and has been growing rapidly in recent years.

Senate Majority Leader Paul Gazelka, R-Nisswa, said controlling health care costs will be the state’s biggest challenge in the years to come.

Despite the compromise, some rank-and-file lawmakers griped that the process ending the legislative session was opaque, rushed and sloppy.

Rep. Rick Hansen, DFL-South St. Paul, expressed the feelings of many of his rank-and-file colleagues still in the dark Tuesday night: “Show up and experience democracy in Minnesota. Bring a flashlight to help look,” Hansen wrote on Facebook.

On Sunday and Monday, lawmakers approved five of the 10 big budget bills needed to finish their work. Those measures included two years of funding for public safety and the courts, environmental protection, natural resources, jobs and economic development, agriculture and higher education.

Gazelka said the legislative session was productive: Before the flurry of activity this week, lawmakers passed a bill bringing the state into compliance with the federal Real ID law, which will allow Minnesotans to board airplanes with a driver’s license. Sunday alcohol sales will be legal July 1. And, lawmakers provided rebates to consumers hit hard by rising health insurance premiums.