Montgomery County health officials have ordered private schools in the county to teach students online-only this fall, a move that sparked immediate blowback online — including from Maryland’s governor — and follows a nationwide shift by public schools toward virtual learning.

The county’s health officer, Travis Gayles, announced the decision late Friday evening, writing that it would take effect immediately and continue through at least Oct. 1. He cited climbing novel coronavirus cases nationwide, in Maryland and in the county. Gayles is one of the first health officials in the United States to require that private schools shutter this fall.

Violating the order would count as a misdemeanor, according to a county news release. Those who break the rule could face up to one year in prison, a fine of $5,000 or both.

“Since the beginning of the COVID-19 pandemic, we have based our decisions on science and data,” Gayles said in a statement. “At this point the data does not suggest that in-person instruction is safe for students or teachers.”

Less than 24 hours after the order came out, Maryland Gov. Larry Hogan (R) denounced it on social media. In a statement posted to Twitter, Hogan wrote that he “strongly” disagreed with closing private and parochial schools.

“As long as these schools develop safe plans that follow CDC and state guidelines, they should be empowered to do what’s best for their community,” he wrote. “This is a decision for schools and parents, not politicians.”

Schools affected include St. Andrew’s Episcopal School, the posh, private prekindergarten through 12th-grade institution in Potomac attended by Barron Trump, the president’s youngest child. The order creates the awkward spectacle in which President Trump’s son could begin the fall semester online, even as his father ramps up pressure on school districts nationwide to reopen their doors as normal. St. Andrew’s officials did not respond Saturday to a question asking how the order changes their plans for the school year.

A day before Gayles’s decision, Trump argued at a White House news briefing that children are not affected by the virus. “The younger, the better,” he said. “They’re stronger. They have a stronger immune system.”

Despite these calls from the president, reinforced by strong words from Education Secretary Betsy DeVos, many of the nation’s largest, most prominent school districts — including those in Los Angeles, Atlanta and Nashville — opted for online-only starts in recent weeks. So has every major public school in the Washington region.

Like Gayles, school leaders elsewhere argued that they had to act because the United States has failed to contain the coronavirus. The country recently hit a dark milestone of at least 150,000 virus-related deaths, according to a Washington Post tally, and at least 4.5 million cases have been reported.

In Maryland, there have been at least 89,000 cases and 3,500 virus-related deaths, per a Post count, and rates of infection rose steadily throughout the month of June. Montgomery County has been especially hard-hit, reporting the second-highest number of cases (more than 17,600) and the highest death count (at least 789) in the state.

As infection rates ticked and then soared upward over the summer, politicians, scientists, teachers’ unions, parents and school administrators went to war over whether and how to reopen school buildings. The science is inconclusive: Although many children do not appear to become seriously ill or die of covid-19, the disease caused by the novel coronavirus, it is unclear how easily they spread it.

A recent report from the Centers for Disease Control and Prevention found that more than three-quarters of the children and staffers at a Georgia sleep-away camp in June became infected after spending less than a week together. Still, guidance on the CDC website recommends that schools reopen, although critics have charged that government health officials are buckling to pressure from the president.

Gayles’s announcement left some parents reeling. Leslie Zarrelli, mother to a junior high student at St. Andrew Apostle School in Kemp Mill, said she feels bewildered and disappointed.

Zarrelli had watched the Catholic elementary and middle school take exhaustive precautions to ensure the safety of its roughly 300 students, preparing for health screenings and spacing out desks. The school, which charges roughly $8,400 per student, had offered families a choice between three models, Zarrelli said: 100 percent in-person learning, three days of in-person learning each week and fully virtual learning.

Zarrelli, confident in the preparations, had picked the first option.

“I know social distancing would have been possible, because I went up to the school and saw the classrooms with the desks apart,” she said. “I felt very comfortable — and now it seems like at the 11th hour, they’re just pulling the rug out from under these schools.”

It’s unfair, she said, that St. Andrew won’t get a chance to try to prove it can hold classes safely.

The order also fueled a fresh explosion of the polarizing debate over school reopenings on social media, a conflict that swiftly split along political lines. Some Twitter users wrote that they were outraged and threatened lawsuits. Others asked Trump officials to take legal action on their behalf.

And conservative commentators were quick to weigh in with charges of despotism.

“Now Maryland is trying to shut down PRIVATE schools,” tweeted Laura Ingraham. “[Gov. Larry Hogan] and Dr. Travis Gayles get ready to be deposed.”

The order appeared to catch many Montgomery County private schools flat-footed — even though Gayles had previously said he did not think it safe for any campuses to reopen.

Half a dozen private schools, as well as the Archdiocese of Washington — which oversees the area’s Catholic schools — did not respond to questions Saturday asking how Gayles’s order affected their reopening plans. Some said they were not prepared to respond.

“We won’t have a comment today,” wrote a spokeswoman for the Landon School in Bethesda.

Throughout the summer, nonpublic schools had forged ahead with plans for in-person instruction. Many spent months developing detailed reopening schemes, envisioning desks set six feet apart and regular temperature-taking. These plans often sought to capitalize on private schools’ smaller size and greater financial resources.

St. Andrew’s, the school President Trump’s son Barron Trump attends, had published in-depth reopening guidelines calling for constant mask-wearing, lunch eaten outdoors, staggered dismissal from classes and “scheduled hand washing times.” These plans were still prominently posted on the school website Saturday morning, along with promises that a final decision on reopening would come the week of Aug. 10. A message from the head of the school, Robert Kosasky, concluded: “I look forward to seeing you on September 8!”

Also on Saturday, the Holton-Arms School in Bethesda still declared in a banner headline: “We look forward to seeing students return for classes on September 8.” The first thing greeting visitors to the website of the Bullis School in Potomac was a pop-up notification asking them to fill out a registration form so they could reserve a seat on a bus route for the 2020-2021 academic year.

A handful of private schools, however, were quick to pivot, such as Sandy Spring Friends School in Sandy Spring. The head of that school, Rodney Glasgow, sent a message to families on the same day of Gayles’s announcement, declaring that classes would be online-only for the first semester, which ends in late January.

Still, Glasgow promised some face-to-face time. The school will create “social pods” of 12 to 16 students, each connected with one faculty member, that will come to campus once every three weeks for “in-person social experiences within their pods,” Glasgow wrote. It will also offer some in-person programming for its youngest students.

“When it is safe to do so, we will return to campus in larger numbers,” he wrote. Glasgow closed with a Winnie the Pooh cartoon, quoting the bear as saying: “We’re going home . . . because that’s the best thing to do right now.”

Stone Ridge School of the Sacred Heart, an all-girls institution in Bethesda, posted a letter to families on Friday that said school would remain closed through Oct. 1, as Gayles had requested.

“We share your disappointment that we cannot begin the school year as we normally would,” wrote the head of the school, Catherine Ronan Karrels. “But we ask you and your families to use this to redouble your commitment to following the advice of public health officials. . . . This is an opportunity for our Stone Ridge girls and for all of us to be role models.”

A key question in coming weeks is whether the enforced private-school pivot to all-virtual instruction will affect tuition. On average in Maryland, private school costs close to $13,000 a year, according to one analysis. But prices can range as high as $60,000.

Private universities have taken a variety of approaches to the problem, in some cases freezing or lowering costs. American University unveiled a 10 percent discount on tuition after telling students the school year would start online, as did Georgetown University.

Neither Sandy Spring’s nor Stone Ridge’s strategies for virtual learning mentioned plans to decrease tuition.