House and Senate leaders broke a weeks-long impasse over a more than $1 billion surplus spending bill Wednesday night, cutting a deal that dropped a controversial corporate tax change.

The tax provision would have financially benefited Massachusetts businesses and set aside $32 million for repairs on the MBTA — less than the $50 million sought by Gov. Charlie Baker.

The vote on the compromise budget bill to close the books on the fiscal year that ended back in June capped a tumultuous day during which Comptroller Andrew Maylor backed off a threat to sweep the entire surplus into reserves by mid-afternoon if the Legislature couldn't resolve its differences.

And before the deal was finalized, House counsel Jim Kennedy got involved in a back-and-forth with Maylor over the breadth of his legal authority, with Kennedy challenging Maylor's assertion of power to sweep the surplus and leave deficits in certain accounts, including MassHealth.

The total spending in the final version of the budget clocked in at $541 million, which was significantly less than previous iterations of the bill that ranged from $723 million to $853 million. Instead of spending more of the surplus, the budget bill proposed to deposit $587 million into the state's "rainy day" fund, pushing the balance of the reserve account to $3.45 billion.

House Ways and Means Chairman Aaron Michlewitz said the compromise reflected an increased level of caution that leaders felt was appropriate after passing a major $1.5 billion, seven-year education funding overhaul and hearing last week from economists about the risk of an economic slowdown in 2020 and beyond.

"Those two factors weighed heavily," Michlewitz said.

The corporate tax provision was widely viewed by those trying to read into the negotiations between the branches over the past several weeks as a major sticking point, and the decision by the House to drop it completely from the compromise came after some liberal Democrats were threatening to hold up any deal that included it.

The provision would have decoupled Massachusetts from the federal tax code, and allowed businesses to avoid paying about $37 million in new taxes as a result of the 2018 Republican tax reform law signed by President Donald Trump that capped the amount of interest a corporation could deduct on debt built up in order to invest in the company. While proponents saw it as a way to foster job growth and capital investment, critics slammed it as an unnecessary corporate tax giveaway.

"To get the budget done, we tried to find appropriate areas of compromise to make sure we got this done," Michlewitz said about the decision to drop it.

Senate President Karen Spilka, who spoke to reporters just after midnight, sounded a similar note when asked about the corporate tax outcome, which reflected the Senate's preference. "All bills have compromise," she said.

One area where conference committee negotiators cut was in funding for the MBTA, which was reduced from $50 million to $32 million to help pay for Gov. Baker's accelerated repair program. The reduction came just days after an outside panel hired by the Baker administration to review the MBTA system identified significant gaps in safety.

House and Senate negotiators also eliminated the targeted assistance funding sought by Gov. Baker for grants to improve the performance in underperforming school districts. Baker had initially requested $50 million, but cut that ask down to $30 million last week.

The completion of the budget came more than a month after Comptroller Maylor's statutory Oct. 31 deadline to close the books on fiscal 2019 and publish an annual financial report. While the fiscal year ended on June 30, Baker did not file the original closeout budget until Sept. 9 and the Democrat-controlled legislature has been at odds ever since over how to spend the surplus.

The bill does establish and fund a period of early voting ahead of the March 3 presidential primaries, but it does not create an early voting window as recommended by the Senate before the 2020 state primary, which the bill scheduled for Sept. 1.

The final version also omits language that would have allowed farmers to use agricultural conservation land for hemp cultivation, even though both the House and Senate have now passed versions of that provision in separate bills.

While Baker must still sign the budget accord, House Minority Leader Brad Jones said prior to the announcement of an agreement that "there should be little or no cause for celebration or congratulations or adulation that this has been resolved."

"It's not the way it should work. The thing we can't have happen has become the new normal," Jones said, comparing a closeout budget accord so long after the Oct. 31 deadline to "turning a term paper in long after a semester is over."

State House News Service's Michael P. Norton and Katie Lannan contributed reporting.