Four teens were charged Thursday in the attack of a girl with special needs that was recorded on cellphone video after she refused to engage in sex acts.

Three girls — ages 13, 14 and 15 — faced charges including aggravated battery and mob action, according to Chicago police. They turned themselves in to police with their parents Wednesday night.

A fourth girl, 15 years old, was taken into custody Thursday afternoon and charged with aggravated battery, police said.

The girl who was targeted in the attack, meanwhile, went missing for several days and was only found the day after video of the incident — posted Monday on Twitter — went viral on social media. She was located Tuesday, five days after her father reported her missing, and she was treated for injuries and released from Comer Children’s Hospital.

She was then taken into protective custody Wednesday as the state Department of Children and Family Services investigates an allegation of neglect, a DCFS spokesman said. The agency has had previous contact with the family, the spokesman said.

The two younger girls charged in the attack appeared together for a hearing Thursday morning at the Cook County Juvenile Justice Center before Judge Terrence Sharkey, each wearing a juvenile detention uniform of a purple shirt and navy sweatpants.

The Chicago Sun-Times is not identifying the girls or their mothers because the girls are charged as minors.

The 13-year-old, who wore her hair long to her shoulders, was released to the custody of her mother and ordered to be placed on electronic monitoring.

“She’s a good girl when she wants to be,” the girl’s mother said after court. The mother added that older girls in the neighborhood were a bad influence on her daughter.

The older girl, who wore her hair short, was ordered to be placed on electronic monitoring, but she will be placed at the Saura Center — a temporary shelter for juveniles who would otherwise be kept in juvenile detention. That girl’s mother had told the judge that she feared for her family’s safety if she returned home.

“I’m fearful for my life and for my daughter’s life,” the woman said. “I don’t think she’d be safe to leave out this courtroom.”

Both parents told the judge they have received multiple threats against their daughters and their families. Prosecutors had asked for both girls to be held in juvenile detention “for their safety.” Sharkey encouraged the families to report any threats to the police, which they said they had already done.

Sharkey told the 14-year-old girl’s mother she would be safe at the Saura Center, adding that she might come back with additional skills her mother would find helpful at home.

“They kind of earn their keep there,” Sharkey said, before listing cooking and cleaning responsibilities the girl would be required to help with at the center.

Both teens were told they could have no communication with each other, or with the 15-year-old they are accused of battering. Sharkey additionally ordered that each girl meet with an educational advocate.

The older girl’s mother said in court that her daughter had stopped going to school in April. She told Sharkey that her daughter needed to be punished.

“We are not here to punish her now,” Sharkey said, later telling the mother to take “a deep breath” and noting that the level of stress for all involved was high.

When the hearing ended, the mother of the older girl wished her daughter a happy birthday as she was led out of the courtroom and cuffed in a hallway.

In the video, the 15-year-old can be seen walking with a group of people when a female in a black tank top and shorts walks behind the girl and punches her. Someone recording the girl starts laughing as more punches are thrown and the girl begins to scream and tries to protect herself.

Several girls then surround her and continue hitting her until she falls to the ground. Just before the video ends, someone appears to help the girl to her feet as she continues to cry.

Chicago Police News Affairs Office Jose Jara said Wednesday detectives are also looking into the possibility that the girl was sexually assaulted while she was missing “based on initial testimony from the victim herself.”

Police said Wednesday that the victim was not reported missing until July 23, the day she was found. On Thursday, though, they said the girl was reported missing by her father on July 18. Her father confirmed he filed the missing person report July 18.

The father, speaking to reporters Thursday evening, also confirmed that his daughter was taken into protective custody as DCFS investigates.

At a news conference at police headquarters Thursday, CPD Supt. Eddie Johnson and Lt. Ozzie Valdez credited community activists and a vigilant citizen for helping police locate the victim.

A passenger saw her aboard a Blue Line train Tuesday on the West Side. From there, she was taken to the CPD’s Harrison District station and later to Comer Children’s Hospital for observation. Police said the girl was treated at the hospital and released.

The top cop added, “If you’re dumb enough to post a crime on social media, that just shows you where your head is.”

Contributing: Nader Issa