It’s over and done.

The Minnesota Legislature and Gov. Mark Dayton have agreed on a nearly $42 billion budget for the next two years, funding schools, parks, nursing homes, tax collections and agriculture programs.

It was not easy. Over the past six months, leaders fought, accused, went into overtime, dropped their top priorities, befuddled and angered.

But at 2 a.m. Saturday, weeks after their targeted finish and hours after most Minnesotans were in bed, the Legislature finished its work.

Dayton, as promised, completed his by signing the budget into law.

Here’s how they got there and what’s ahead:

WHAT DID LAWMAKERS AND THE GOVERNOR DO THAT THEY THINK WAS SO GOOD?

Everyone involved in this year’s sometimes-painful legislative decisions may pick a different highlight, but most agree that they are pleased that:

— Despite divided government, Minnesota will not experience its third state government shutdown in the past decade.

— Public schools will receive increases in their budgets of 2 percent in each of the next two years. While that agreement was hard-fought and the increase was higher than all Capitol powers’ initial proposals, the extra cash will give schools more certainty through 2017.

— Nursing homes got $138 million in extra state funding as part of a wholesale reform of how Minnesota reimburses them through its Medical Assistance program.

WHAT DID THEY DO THAT THEY THOUGHT WAS BAD?

In part because of the divided government and because key players had trouble getting along, this year’s business at the Capitol was messy, long and lacked transparency. While those are often hallmarks of Minnesota’s legislative system, there was a bipartisan hue about the closed-door, dark-of-night shenanigans.

The governor, the Republican House and the Democratic-Farmer-Labor Senate also failed to agree on any major transportation investments. Despite coming together on a belief that the state’s road, bridge and transit infrastructure needs about $7 billion more in spending over the next decade to serve the state, they were stymied on whether to tax, borrow or shift their way to find that money.

WHAT DID DAYTON WIN AND LOSE?

The DFL governor came into the legislative session talking of several big priorities, including transportation and universal preschool funding. He quickly added a vegetative buffer program across the state to protect Minnesota’s waterways from pollution.

He failed to win any big transportation investments and failed to get lawmakers to enact universal pre-K, though he did win significant new investments in existing education programs. The Legislature also approved a buffer program, but it was not nearly as ambitious as Dayton wanted.

WHAT DID REPUBLICANS WIN AND LOSE?

Republicans in the Legislature were set against any tax increases for transportation, and no tax increases were approved. But they, too, wanted big spending on roads and bridges, which didn’t happen.

The Republican House also crafted health care plans to dramatically change MNsure, the state’s health exchange program; and to eliminate MinnesotaCare, a subsidized health insurance program for the working poor. The GOP further pushed a plan to cut taxes by $2 billion and trim state spending by about the same amount. None of that happened.

In a political win that may pay dividends, the Republicans in the House kept united and kept faith with their newly elected speaker, Rep. Kurt Daudt, R-Crown.

WHAT DID SENATE DFLERS WIN AND LOSE?

Again, the lack of a transportation investment package was among the Senate’s top priorities. That was thwarted.

DFLers also wanted to give more cash to schools, higher education, health care and other state government programs. They largely managed that, despite Republican attempts to cut state spending.

Senate DFLers ended the year in disarray, with largely liberal urban DFLers rising against their outstate leaders, including Senate Majority Leader Tom Bakk of Cook. In particular, environmental measures tore the DFLers apart, requiring Republican votes to approve parts of the budget and casting doubts on Bakk’s longevity in leadership.

“There are caucus members not happy with the environment bill, for sure,” he said. “And I serve at the pleasure of the caucus.”

WHAT HAPPENED IN THE SPECIAL SESSION?

Getting to the one-day special session was messy — filled with breakthroughs and breakdowns, demands unmet and more demand levied. In the end, just 11 hours before lawmakers convened, Dayton signed his name to a proclamation declaring: “I … do hereby summon you, members of the Legislature, to convene in special session.”

At first, despite using temporary chambers set up in the State Office Building, all went smoothly. By generally large margins, the House and Senate approved measures to fund education and economic-development budget plans to replace those Dayton vetoed. And they passed Legacy Act spending for the outdoors and the arts.

But then came an environment and agriculture budget bill. The DFL-controlled Senate, which had needed Republican votes to approve the environmental regulation measure in May, came just one vote shy of approving the measure Friday. While a personal plea from Dayton led several DFLers to add their support, the Republican vote had dropped off since the bill passed in May. Disarray ensued.

After hours of discussion, DFLers in the Senate changed the bill to remove two provisions opposed by environmentalists — a violation of the “no amendments” agreement that is typical of special sessions. That passed with big DFL support, but the Republican House refused to go along. Stymied, a minority of Senate DFLers joined with almost all Republicans to pass the original bill. Dayton signed that budget bill and all the rest into law Saturday.

WHERE DID THOSE REPUBLICAN VOTES COME FROM?

After holding back support for the environment measure early on Friday, Republican Senators overwhelmingly approved it in the wee hours Saturday.

Senate Minority Leader David Hann, R-Eden Prairie, said he had talked to Bakk and won a promise that the DFLers would work with Republicans next year on “significant tax relief. … That was enough as I went back to our caucus.”

Bakk said he made that pledge but also had been talking for months about tax reductions in the 2016 session, which happens to be an election year.

WHAT HAPPENS NEXT YEAR?

While bitter feelings may linger into 2016, the good news is that the budget is done. The Legislature’s main task next year is to approve a larger borrowing bill for statewide projects.

Given that, they do not plan to meet again until March. That late date might be helpful — the Capitol’s multiyear construction project will make much of it unusable next year.

Lawmakers and the governor also are hopeful that they will approve the transportation plans they left behind in 2015.

“I’ll push for it. I don’t think it can wait,” Dayton said.

But that, too, could be a problem, with some lawmakers doubting a huge spending package with possible tax or fee increases can pass in an election year.