Roberto Carlos Magalhaes told detectives that a woman who went into a trance would "command him to stick the needles in the boy's body," police inspector Helder Fernandes Santana said in a telephone interview with The Associated Press.
"According to his confession, he acted under influence of the woman, but it was him who stuck the needles in the boy's body," the inspector said. He said three people, including the stepfather and the woman, have been arrested, though no charges have yet been filed.
An enraged crowd of more than 100 people surrounded the police station where the suspects were held Wednesday night, hurling rocks at the building. Santana said they broke out a window of his own car because they wrongly believed the suspects were in it.
Extra police were called in to restore order and protect the suspects.
The child, meanwhile, was airlifted to the heart unit of a major hospital in northeastern Brazil Thursday because two of the needles are close to his heart, but it was not immediately clear when doctors might be able to remove them.
Surgeons at a hospital in the town of Barreiras in Bahia state, where the boy had been hospitalized since Sunday had decided not to try to remove any needles immediately for fear they could cause more damage.
Doctors located 42 needles in the boy, who was in stable condition in the coastal city of Salvador after a 240-mile (390-kilometer) flight to a hospital with a special heart unit.
Hospital spokeswoman Susy Moreno said an evaluation of how to treat the boy probably would not be finished until Friday.
The boy's mother, a maid, took him to a hospital in the small northeastern city of Ibotirama on Dec. 10, saying he was complaining of pain. Three days later, after X-rays revealed many of the needles, doctors moved him to the larger hospital in the nearby city of Barreiras.
The mother told police she didn't know how the needles got inside her son, whose name was not released because of his age.
The boy's father, Gessivaldo Alves, told the newspaper A Tarde that he believed his son could have been a victim of a black magic ritual. Alves reportedly said he visited the home where the boy was living and found unspecified items that could be used for black magic.
Santana said police are investigating to determine what sort of religious sect the stepfather and the women belonged to.
One of the doctors who treated the child, Luiz Cesar Soltoski, said he believed that the needles were stuck into the child's body one by one.
"We think it could have only been by penetration because we found needles in the lung, the left leg and in different parts of the thorax. It couldn't have been by ingestion," Soltoski said.
Doctors found no signs of outside wounds on the boy. X-ray images carried by Brazilian Web sites clearly showed some of the needles deep inside his body.