It’s the little elementary school that could.

After a yearlong legal battle, the city’s education department announced Thursday it will spare P.S. 25, a Brooklyn elementary school, from closure.

The sudden about-face means that a key legal question about school closures and attendance zones will not be immediately resolved. Advocates argued the city violated one of the few formal powers of local parent councils in closing the school. The closure has been on hold since last summer, when a judge ordered the education department to keep the school open while the case proceeded.

Schools Chancellor Richard Carranza made the decision after reviewing the situation and “listening closely to District 16 parents,” education department spokesman Doug Cohen wrote in an email. “This gives P.S. 25 clarity and stability moving forward, and we’re excited to continue our work with the school to support a high-quality and sustainable learning environment,” Cohen added.

That represents a complete reversal from early last year, when district officials said the elementary school suffered from low and dwindling enrollment and was unsustainable. The school’s enrollment fell to 82 students this school year, down from 102 the previous year, and is projected to cost $50,000 per student to operate, officials said. (That projection is based on a lower enrollment of 60 students; it is not clear what the current spending figure is.) The department has previously argued schools with enrollments that low are too costly to keep open and struggle to offer a full range of programs.

The change came just before a legal hearing in the case Thursday morning, but also signals Carranza’s reluctance to shutter schools, a process that proved controversial for his predecessor. The decision to close P.S. 25 was made before Carranza took office, and no closures have been proposed since.

Advocates for P.S. 25 argued that the city’s efforts to close the school didn’t make sense because it has improved significantly in recent years, according to state tests. About half of its students are proficient in reading and 70 percent are proficient in math, above city averages.

“The school is doing extremely well for an extremely high-need school population,” said Leonie Haimson, executive director of the advocacy group Class Size Matters who has pushed to keep the school open. The school is 92 percent black and Hispanic, and virtually every student comes from a low-income family, city data show.

Parents and advocates, including Haimson, also filed a lawsuit to save the school, arguing the city didn’t have the legal authority to unilaterally close it.

Typically, the education department can close schools without approval from local parent councils. But since the councils have authority over how school zones are drawn, and P.S. 25 is the only zoned elementary school for a swath of Bedford-Stuyvesant, the lawsuit argued that closing the school amounted to “unlawfully usurping” the local education council’s authority.

This isn’t the first time a legal argument about school zone lines has gained traction. A similar lawsuit filed in 2009, and joined by the city’s teachers union, prompted the city to reverse efforts to replace three elementary schools with charter schools.

In a twist, the local education council in this case originally supported the plan to close P.S. 25, meaning that even if the lawsuit had prevailed, it’s possible the council would have voted to close the school.

But on Thursday, the District 16 parent council president, NeQuan McLean, said the council now supports the decision to keep the school open. McLean said the change of heart was due to assurances from department officials that they would assist with a plan to help attract families to the school and support other schools in the district.

“We are confident that the [education department] is going to help promote the school,” McLean said. “We believe this is what’s best for this school at this point.”

Correction: Due to incorrect information provided by an education department spokesman, an earlier version of this story suggested the per-student spending at P.S. 25 is $50,000 this school year. In fact, that is a projection.