Less than a year after Success Academy lost a battle to open a new middle school in a building shared by a small Brooklyn elementary school, city officials confirmed Wednesday that they plan to give the charter network the green light to open in that space starting next school year.

Success Academy Lafayette, a middle school that was forced to open in a different building this school year, will now likely move into the P.S. 25 building in Bedford-Stuyvesant — a year later than the charter network had hoped.

The decision is a belated victory for Success Academy, though it must still go through a public hearing process and a vote from the city’s Panel for Educational Policy.

But the broader story about Success Academy’s fight for space in the P.S. 25 building is far more complicated and is related to a separate and fraught court battle over whether a district elementary school as small as P.S. 25 should be allowed to remain open. To understand this latest move, it helps to know the complicated backstory behind this single Brooklyn school building.

Why did the city delay Success Academy opening a middle school in the first place?

It’s not uncommon for the city to butt heads with Success Academy over school space, so on some level it’s not surprising that there was a dustup. But in this case, Success had already been operating an elementary school in the building and had decided to move those students elsewhere and replace it with a middle school.

Normally charter schools must go through a public hearing process when they make a significant change like this to the way they use a school building, especially in cases where they share facilities with a district school.

Success assumed there would be no need to go through that process, since it looked as though the school operating in the building, P.S. 25, also known as the Eubie Blake School, would be closed. Then came a lawsuit challenging the city’s decision to close the school — and a judge’s ruling that P.S. 25 should stay open while the case continues to wind its way through court.

That created a problem for the charter network: By the time it became clear the district school would remain open, it was too late for Success to go through the formal public approval process. The network’s CEO Eva Moskowitz and parents called on the city to approve the middle school anyway on an emergency basis, but the education department declined to act. The result: Success wasn’t allowed to open a middle school in the building this school year. Instead, it opened in a building less than a mile away. (The network did not respond to requests for comment on Wednesday.)

If P.S. 25 closes, another charter school could open in the building

It’s unclear whether the city will be allowed to follow through on its plan to shutter P.S. 25. But if the closure goes through, the education department will likely reserve the space for another charter school, officials said Wednesday.

“We are working with District 16 and Success to meet the needs of our students and families,” education department spokesman Doug Cohen wrote in an email.

NeQuan McLean, president of the District 16 Community Education Council, said that while he does not generally support the growth of charter schools in the district, it is better to allow charter schools to share space with each other instead of with district schools.

“We have agreed as a community and a CEC to make that a charter building,” he said.

What’s up with the court battle over P.S. 25?

The lawsuit to keep P.S. 25 open banks on a complicated argument about how much power local community education councils have in school closure decisions.

Under state law, the councils have the authority to approve any changes to school zones and typically don’t have any power to block school closure decisions. But since P.S. 25 is the only zoned elementary school for a swath of Bedford-Stuyvesant, the department’s plans would leave some families with no zoned elementary school dedicated to educating the neighborhood’s children, forcing students to attend other schools in other districts or to enter the admissions lottery for charter schools.

That amounts to “effectively attempting to change zoning lines” and “unlawfully usurping” the local education council’s authority to determine those zones, according to the lawsuit.

It’s possible that argument will gain traction. A similar lawsuit filed in 2009, and joined by the city’s teachers union, prompted the city to reverse plans to replace three elementary schools with charter schools. (A favorable legal outcome for the P.S. 25 parents could affect the procedure for closing schools in the future, but only if they are also zoned.)

The school’s supporters also argue that the school’s performance makes it an odd choice for closure: its state test scores last year put it among the highest-ranked elementary schools in the city. That stellar performance, however, could partly be the result of natural statistical swings in scores that can occur in schools that serve so few students. (The school’s math scores have shot up from 22 percent of students passing in 2015 to over 70 percent last school year.)

“All those kids will literally be forced to leave an excellent school that has managed to provide small classes and proven itself many times in terms of results,” Leonie Haimson, executive director of the advocacy group Class Size Matters and a supporter of the lawsuit, wrote in an email.

Just 87 students are currently enrolled in the school, which is projected to spend nearly $50,000 per student this year, roughly double the city average. (That number could fluctuate this year, since more students appeared to have enrolled than the city expected, but final numbers won’t be available until later this fall.)

Still, no matter what happens in court, it is unlikely P.S. 25 will remain open. Even if the lawsuit forces the education department to abide by a vote from the local education council, its members want the school to close, its president said.

“If the question is would we be willing to change the zone lines so that the DOE would be able to close the school? The answer is absolutely,” said McLean, the community education council president.

Editor’s note: This story has been updated to clarify that spending per student at P.S. 25 is based on a city projection.