This summer, parents rallied at the steps of City Hall and crammed into town hall meetings to demand space for a new Success Academy charter middle school. The network’s combative CEO penned an open letter calling on the mayor to act.

After a last-ditch attempt to secure an emergency order that would have allowed Success Academy Lafayette to open inside a Brooklyn elementary school, the city’s largest charter network gave up its fight.

The principal of the new school emailed parents Thursday to say it would instead open less than a mile away, inside a building that already houses Success Academy Myrtle Middle School.

“With less than a month before school starts, we can’t wait any longer,” wrote principal Kristin Damo.

The retreat marks another chapter in a bitter and long-running battle for space for charter schools. While Success CEO Eva Moskowitz has accused the city of dragging its feet to give the charter network room in district buildings, the education department says finding suitable spaces to share is often tricky.

The network’s latest plans were dashed by a fraught legal battle to keep a tiny district school open.

Success had planned to open inside P.S. 25, also known as the Eubie Blake School, a Bedford-Stuyvesant elementary school that had been slated for closure by the education department after enrollment plummeted — it’s slated to enroll just 60 students in the fall. But P.S. 25 was granted a reprieve after parents sued, and a judge blocked the closure until their case is heard.

The charter network had already operated an elementary school inside P.S. 25 and planned to convert the space into a middle school for grades five through eight. Success transferred its elementary students to other locations to make room for about 70 middle schoolers. Then came the judge’s decision to keep P.S. 25 open.

In a letter to Success Academy parents, the education department said the legal battle prevented the middle school from opening.

“The judge has ordered that P.S. 25 remain open while litigation is pending, preventing us from siting a new Success Academy middle school in the building,” Deputy Chancellor Elizabeth Rose wrote in a June 22nd letter.

The problem came down to timing, according to education department spokesman Doug Cohen. The city needs to study how the district school and charter school would share space in the same building, but the surprise decision to keep P.S. 25 open meant the education department couldn’t meet the required deadline to do so.

Success supporters held out hope that schools Chancellor Richard Carranza would issue an emergency order at a city meeting Wednesday night to allow the middle school to open as planned. Officials for the charter network say there is still room for them in the building, since they don’t plan on taking any more space than their elementary school had.

But the city declined to act, and Success relinquished the battle for now. Success spokeswoman Anne Michaud said the network hasn’t given up its push to find the middle school a permanent home, but needed to move forward for the coming year.

“School is starting in less than a month,” Michaud said. “People need to make plans.”

Clarification: This story has been updated to clarify when the judge’s order to keep P.S. 25 open was issued.