NEW YORK (AP) — New York City is shuttering schools to try to stop the renewed spread of the coronavirus, Mayor Bill de Blasio said Wednesday in a painful about-face for one of the first big U.S. school systems to bring students back to classrooms this fall.

The nation's largest public school system will halt in-person learning Thursday, the mayor and schools chancellor said.

The city had said since summer that school buildings would close if 3% of all the coronavirus tests performed citywide over a seven-day period came back positive. As the rate neared that point las week, de Blasio advised parents to prepare for a possible shutdown within days.

The mayor said the rate has now passed that mark.

The city's more than 1 million public school students will now be taught entirely online, as most already are. As of the end of October, only about 25% of students had gone to class in school this fall, far fewer than officials had expected.

In-person school resumed Sept. 21 for pre-kindergarteners and some special education students. Elementary schools opened Sept. 29 and high schools Oct. 1.

At the time, the seven-day positive test average rate was under 2%.

Even as the school system stayed open, more than 1,000 classrooms went through temporary closures after students or staffers tested positive, and officials began instituting local shutdowns in neighborhoods where coronavirus cases were rising rapidly.

New York City's school system, like others across the nation, halted in-person learning in mid-March as the virus spiked.

While many big U.S. school districts later decided to start the fall term with online learning, de Blasio pushed for opening schoolhouse doors. The Democrat argued that students needed services they got in school and that many parents were counting on it in order to get back to work.

To keep students spread out, the city offered in-person learning only part-time, with youngsters logging on from home the rest of the time.

The reopening date, originally set for Sept. 10, was postponed twice as teachers, principals and some parents said safety precautions and staffing were inadequate, with the teachers' union at one point threatening to strike.

The city agreed to changes, including hiring thousands more teachers and testing 10% to 20% of all students and staffers per month for the virus.

When high schools finally opened their doors, de Blasio hailed it as “an absolutely amazing moment” in the city's recovery.

“This is an example of what makes New York City great,” he said at the time. “We did something that other cities around this country could only dream of because we have fought back this pandemic so well for so long.”