CHICAGO (AP)  Chicago teachers and the nation’s third-largest school district struck a tentative deal on a new contract late Monday, averting what would have been the second major strike since 2012 for Chicago Public Schools just hours before union members were set to hit the picket lines.

Chicago Teachers Union President Karen Lewis said at a news conference just before midnight Tuesday that after more than a year of negotiations, the two sides had hammered out an agreement that isn’t perfect but is good for students, teachers and the city.

The deal still must be approved by the union’s House of Delegates and the full membership, a process that could take weeks.

“There will be classes in the morning,” she said. “It wasn’t easy as you all know … we’re very pleased we were able to come to this tentative agreement.”

Chicago Mayor Rahm Emanuel said the proposal ensures teachers are respected and “appropriately rewarded.” He said it also would strengthen CPS finances and reassure parents and taxpayers that the two sides were able to work together. There was no immediate information about how much the deal would cost or how the financially struggling district would pay for it.

“Students across Chicago will be in school this morning and on the path to a stronger and brighter future,” Emanuel said at an early morning news conference at City Hall.

The four-year proposal includes cost-of-living increases of 2 percent in the third year and 2.5 percent in the fourth year. It doesn’t require current teachers to pay more toward their pensions  a change CPS had been seeking and the union rejected earlier this year. Future CPS hires would have to pick up that additional pension cost. The tentative agreement also addresses class sizes for younger grades by assigning an assistant to any class with more than 32 students.

The CTU had directed its roughly 28,000 members to report to picket lines Tuesday morning unless they heard otherwise from union negotiators for a walkout that would have affected nearly 400,000 students.

The two sides held negotiations throughout the weekend. On Monday afternoon, teachers picked up strike placards and painted banners. Earlier in the day, parents and other supporters rallied across from Mayor Rahm Emanuel’s home.

“Nobody wants to go on strike but I think the teachers finally said ‘Enough is enough,'” Nate Rasmussen, a preschool teacher at Beasley Elementary School on the city’s South Side said prior to the tentative deal. He said the district’s 2013 closing of some 50 schools, layoffs of thousands of teachers in recent years and other spending cuts have made the job tougher.

Teachers have been without a contract since June 2015. The union wanted no cuts to salary or benefits and an additional $200 million  or $500 per student  in spending to ensure adequate staffing and “to accommodate the needs of our children,” Lewis said on Friday.

CPS had been working within the framework of a January offer, which included pay increases and a cap on privately operated charter schools but would have required all teachers to contribute more to their pension costs. The union turned it down in February.

CPS officials say the district is facing serious financial constraints, due largely to soaring pension costs and a flawed state school funding formula.

About two-dozen people with Parents 4 Teachers rallied in Emanuel’s leafy Ravenswood neighborhood on the city’s North Side Monday morning.

Organizer Erica Hade has several children in the public school system and lives across the street from a school. She said she sees teachers arriving for work at 6 a.m. and leaving 12 hours later.

“How can parents not be supportive of teachers?” she said.

Jim Tormey, a 52-year-old father of two children who attend CPS, spoke with the demonstrators. Afterward, he said he had some sympathy for teachers but that his feelings were mixed.

“There are ebbs and flows in that sympathy,” he said. “We love our teachers, but we want our kids not to miss school because of a strike.”

During the last major strike in 2012, teachers were out for seven school days.