A Massachusetts man accused of giving drugs to a 13-year-old girl and then dropping her off at a hospital where she soon died was charged Tuesday with aggravated rape of a child, prosecutors said.

Carlos Rivera, 47, was in court for a dangerousness hearing when he was instead arraigned on the rape charge following new evidence in the death of the girl. Preliminary results from an autopsy on the 13-year-old linked Rivera's DNA to her, the Essex District Attorney's Office said.

Rivera, who was arrested on May 25, was arraigned last week on two counts of distribution of cocaine to a minor, two counts of indecent assault and battery on a child under 14, and one count of indecent assault and battery on a person 14 or over.

The district attorney's office said last week that Rivera was also accused of indecently assaulting another girl, who is 16. That alleged assault was discovered during the investigation regarding the 13-year-old.

Detectives said he left the 13-year-old at Lawrence General Hospital on May 20. She died shortly after arriving. The cause and manner of her death have not yet been revealed, the district attorney's office said.

According to investigators, Rivera was accompanied by another girl, who was under 16, when he dropped off the 13-year-old at the hospital. Detectives said both girls were at Rivera's apartment prior to the 13-year-old's death.

The 13-year-old girl's mother told the Boston Globe that she dropped her daughter off at a friend's house in Amesbury and became worried when she had not heard from her. After texting some of her daughter's friends, the mother said she learned that the girl had been taken to the hospital.

Rivera is being held without bail and is expected to appear in court for a probable cause hearing on July 2.