Authorities said the girl, who had assembled a collection of butcher knives and other straight-edged weapons, may have been inspired by the massacre in 2015 at a storied African American church in Charleston, South Carolina, carried out by an unrepentant white supremacist.

Police found out about the plot after high school students in Gainesville, Ge orgia, confided to a counselor that a classmate had a notebook containing “detailed plans” for killing congregants at the Bethel African Methodist Episcopal Church, authorities said. School officials reported it to authorities Friday.

“Our investigation indicated the church was targeted by the juvenile based on the racial demographic of the church members,” Chief Jay Parrish of the Gainesville Police Department said in a statement Tuesday.

The student, who was not identified by authorities, was charged with criminal intent to commit murder, police said. She was being held Tuesday in a juvenile detention facility.

Police officials said that the girl visited the church last Wednesday evening, a time when Bible study is usually held. “Through divine intervention or whatever you want to call it, they weren’t having services that evening,” Sgt. Kevin Holbrook, a spokesman for the Gainesville police, said in an interview.

It was not clear whether she was planning to carry out the attack that evening, he said, or gathering information for later use.

“We are thankful to God that this plot was stopped before anybody was either killed or injured,” Bishop Reginald T. Jackson, the presiding prelate for the African Methodist Episcopal Church’s more than 500 congregations in Georgia, told reporters in his office in Atlanta.

The Bethel congregation, which has about 40 members, worships in a small white sanctuary perched on a corner in a residential neighborhood of Gainesville, a city of about 40,000 people an hour’s drive northeast of Atlanta. The African Methodist Episcopal denomination was one of the first Protestant churches created by black people and has several thousand congregations around the country.

The Rev. Dr. Michelle Rizer-Pool, Bethel’s pastor, said that she went to the church to pray as soon as she heard of the plot last week. And Sunday, she said, she comforted her congregation, who were stunned and hurt by the news.

“I tried to let them know, let us not be afraid,” she said, adding that she sought to impress upon them that “God is with us.”

The plot has been an unwelcome reminder of the massacre June 17, 2015, at Emanuel AME Church in Charleston, the denomination’s oldest congregation in the Deep South and one with a rich two-century history of resisting slavery and supporting the civil rights movement.

In that attack, a 21-year-old white man fueled by racial hatred sat through Bible study and then opened fire, killing nine people. The gunman, who was condemned to death by a federal jury in 2017, wrote in a jailhouse manifesto that he “would rather live in prison knowing I took action for my race than live with the torture of sitting idle.”

Law enforcement officials have said they believe that the Charleston attack, which rattled the nation, has incited would-be imitators, like a 29-year-old South Carolina man in 2017 who told an undercover federal agent, from whom he was buying a handgun, that he had plans inspired by the Charleston gunman.

And in the case announced Tuesday, Holbrook said the Charleston attack “does appear to have played some type of role in this.”

News of the plot renewed fears about the security at houses of worship, including churches and synagogues, which have been targeted repeatedly in recent years. It came at a time when hate crimes have been increasing, reaching a 16-year high last year, according to federal crime data.

“I want to be wrong,” Jackson said, “but these kinds of incidents, unfortunately, have a way of encouraging others who share the same ideology.”

Church officials said they would urge prosecutors to charge the girl as an adult, saying that the plot was not the product of a “childish mind.” The district attorney whose jurisdiction includes Gainesville did not immediately respond to a message seeking comment Tuesday.

“We love her — we’re going to pray for her,” Jackson said. But he added that the situation brought to mind a lesson he has preached many times: “For every decision you make, there’s consequences.”