At long last, state lawmakers have reached a deal on rescuing Atlantic City from bankruptcy.

Statehouse leaders have been battling for months over whether New Jersey should take over the seaside resort’s operations. The final agreement gives the city five months to come up with a plan for balancing its own budget for the next five years. If it fails, then the state could take over.

Atlantic City will also receive a bridge loan from the state to cure a deficit in its current budget. It will receive casino funds to make payments on debts. And it will receive a pledge for increase state aid in the future, which could help the city have the collateral needed to refinance its roughly $250 million in debt.

Mayor Don Guardian said “it’s going to be a tough road” for city and union officials to make the cuts needed to balance the budget, which will require spending to be cut by more than one-fourth.

“I do want to thank you,” Guardian told lawmakers. “I realize that you have been able to do very little New Jersey state business because of the amount of time that you’ve taken for my city. But I do want to thank you ahead of time for saving my city.”

“I want to thank you for the pain that it has taken,” Guardian said. “But I tell you that the pain will be worth it because we will succeed. We’ll be resilient. We’ll be healthy again.”

The issue has grown into a paralyzing political fight in Trenton that defied party labels, pitting Republican Gov. Chris Christie and Senate President Stephen Sweeney, a Democrat, on one side with Assembly Speaker Vincent Prieto, a Democrat, and Guardian, a Republican, on the other.

The solution is a modified version of the bill Christie backed that was passed by the Senate. It adds a grace period of 150 days, similar to what Sweeney mentioned as a path to compromise, though it does not specify that the plan would need to identify how to cut spending by nearly half.

“We have given them, to the best of the ability, a fighting chance. Atlantic City will have now time to be able to take care of their own house,” said Prieto, D-Hudson. “I wish I could be here today and we could say there was going to be a chicken in every pot for everybody in Atlantic City, but that’s not the case.”

“We want nothing more than for this to succeed,” said Assembly Majority Leader Louis Greenwald, D-Camden, “and for the public to understand this will not be the equivalent of coming in and flipping a switch and that everything will be better. This is going to take a lot of work, a lot of effort, a lot of sacrifice. But Atlantic City will be better for it in the long run.”

Prieto estimated that the cuts to the city's $262 million budget may have to amount to $88 million to $100 million. Guardian didn't commit to an amount but said the spending would likely have to be reduced to a little bit below $200 million.

“It’s going to be pretty drastic," said Guardian, who projected the city could save $20 million to $30 million a year in spending by refinancing its debt and as much as $7 million through the early retirements of police officers and firefighters.

Atlantic City faces staggering deficits in part because of the collapse of the city's casino industry. Four of the city's 12 casinos have closed, and others have significantly lowered their property values through successful appeals.

The bill eliminates a provision that had been talked about earlier that would have allowed Atlantic City casinos to opt-out of making agreed-upon payments in lieu of property taxes if casinos are built in North Jersey, as envisioned by a proposed constitutional amendment voters will decide in November.

Lawmakers believe Christie will sign the bill, given that his office was in the loop during negotiations, though he didn't offer a public statement in the immediate wake of the Assembly Judiciary Committee's approval of the compromise.

Sweeney, D-Gloucester, didn’t want to say much about the agreement in advance of the Assembly vote, noting that deals have appeared to be at hand before only to fall apart, like Lucy pulling away the football in the Peanuts comic strip.

“I’m a little bit tired of being Charlie Brown, so we’ll wait,” Sweeney said.

Sweeney said the Senate would move up a voting session from next Thursday to this Thursday to consider the Atlantic City bills on the same day the Assembly is expected to pass them.

“We didn’t want this to be a political football the way it turned out,” Sweeney said. “The people of Atlantic City should be first and foremost. The taxpayers of that city are getting crushed. We’ve got to worry about Atlantic City more than anything else.”

More From New Jersey 101.5 FM