Lawmakers in the state Assembly and Senate have finally passed a deal on mayoral control of New York City’s public schools, giving Mayor Bill de Blasio a two-year extension — his first multi-year deal since taking office in 2014.

The Senate passed the bill Thursday afternoon, just one day before mayoral control was set to expire on June 30 at midnight. It was signed into law by Governor Andrew Cuomo shortly after 3 p.m.

Included in the so-called “big ugly” are also measures renewing a slate of local taxes and renaming the Tappan Zee Bridge for the late Governor Mario Cuomo. The bill language does not include any provisions benefiting the charter school sector, which Senate Republicans had initially hoped to get in exchange for mayoral control.

RELATED: How does Bill de Blasio grade on his education promises?

Perhaps most notably, the bill gives de Blasio two years of mayoral control. Though former New York City Mayor Michael Bloomberg had mayoral control deals for six and seven years, de Blasio had until now failed to secure more than a one-year extension — despite his repeated requests for multi-year deals.

“Providing a two-year extension gives the system an important measure of stability that’s key to initiatives that have produced record achievement,” the mayor said in a statement. “Our state government’s action allows us to refocus our attention away from the political process and back to our classrooms, where it belongs.”

After a long day of closed-door meetings between the governor and leaders of both parties, the agreement was hashed out by Assembly lawmakers in the early hours of Thursday morning during a special legislative session called by Cuomo. The regular legislative session had already ended last Wednesday with lawmakers failing to come to an agreement on mayoral control.

It remained unclear Thursday morning if Senate Republicans would go along with the Assembly bill. At around 1 p.m., Senate Democratic Leader Andrea Stewart-Cousins released a statement, calling Thursday “another day and another example of dysfunction in the Senate,” and asking Republicans to wrap up their discussion and bring the bill to the floor for a vote.

Just after 2 p.m., Senate Republicans did just that and the bill passed the Senate with a 48–2 vote, with Republicans Terrence Murphy and James Tedisco voting against it.

“We came to a responsible agreement that extends mayoral control of the New York City schools for two years while ensuring that charter schools continue to play an important role in the education of schoolchildren there,” Senate Majority Leader John Flanagan said in a statement shortly after the bill passed.

RELATED: Flanagan's standoff with de Blasio tops post-budget agenda

Flanagan tried unsuccessfully to link mayoral control to charter school expansion. The state Senate passed a series of bills earlier this year with different options for tying the extension of mayoral control to school choice, including lifting the cap on charters in New York City.

But trading mayoral control for charter school concessions was a “non-starter” for Assembly Leader Carl Heastie, leading to last week’s impasse.

If a deal had not been reached by the June 30 deadline, New York City schools would have reverted back to a disjointed system with 32 community school boards — an outcome many were eager to avoid.

Monica Disare contributed reporting.

This story was originally posted on Chalkbeat, a nonprofit news site covering educational change in public schools.