TRENTON - New Jersey lawmakers have agreed on an Atlantic City rescue package to keep the struggling gambling resort city from running out of money.

Leaders of the state Assembly and Senate reached agreement Monday on a package of bills to help the nearly broke city, giving it five months to devise a plan for balanced budgets over the next five years.

The city would get a temporary loan of about $60 million, would be able to offer all its employees early retirement, and would retain its collective bargaining rights - something that would have vanished under previous proposals.

Casinos would not be allowed to opt out of a payment in lieu of taxes plan, even if voters authorize casinos in North Jersey.

Lawmakers have been battling for weeks over the plan. Gov. Chris Christie and Senate President Steve Sweeney backed a plan for an immediate state takeover of Atlantic City. 

However, Assembly Speaker Vincent Prieto blocked their plan and stood with Atlantic City Mayor Don Guardian. Prieto said the takeover would terminate collective bargaining rights and could eliminate union contacts.

Mayor Guardian thanked lawmakers for coming to an agreement, and promised that Atlantic City would prosper once again.

“I do want to thank you ahead of time for saving Atlantic City, from all our residents and businesses,” Guardian said. “I assure you, we're going to come back and be very proud and we are going to be a good cash cow once again for the state so that we all benefit.”

Atlantic City officials have until the end of the year to come up with a plan to repair the city’s finances before the state can take over.

The full Assembly will vote Thursday on the changes. The plan must also be approved by Gov. Christie before Atlantic City can get the loan.

The Associated Press wire services contributed to this report.