The authorities in Charlottesville, Va., arrested a 17-year-old boy on Friday in connection with an online threat targeting black and Hispanic students, bringing a sense of relief to a saga that had forced the closing of the city’s public schools for two straight days.

The teenager, who was not identified, is believed to have published a post on the web forum 4chan that threatened an “ethnic cleansing” at Charlottesville High School, the authorities said.

The post set off a rapid investigation and prompted the Charlottesville public school district, which serves about 4,300 students from kindergarten to high school, to shut down all of its campuses on Thursday and Friday.

By midday Friday, the Charlottesville Police Department had announced that a suspect was in custody and had been charged with threatening to commit serious bodily harm on a school property, as well as harassment.