The woman, Angelina Ribeiro dos Santos, paid to have the needles blessed by a woman who practices the Afro-Brazilian religion Candomble and convinced Magalhaes that inserting them into the boy would somehow allow them to be together, Santana said. Police, however, believe she was out for revenge on the mother.
The two held sessions every few days over a full month in which Magalhaes stuck the needles into the boy several at a time, Santana said.
"According to his confession, he acted under influence of the woman, but it was he who stuck the needles in the boy's body," the inspector said. Magalhaes and dos Santos were arrested, though no charges have yet been filed.
Dos Santos is not believed to be a member of any religious or occult group, and authorities believe she came up with the idea of the rituals on her own, Santana said.
Authorities also detained the woman who blessed the needles so she could be questioned, but Santana said he expects she will be released without charge because she did not know how they were being used.
Magalhaes denied involvement when he was first questioned on Monday, but confessed after police detained him on Wednesday, Santana said.
An enraged crowd of more than 100 people surrounded and hurled rocks at the police station in the small northeastern city of Ibotirama, where the suspects were held Wednesday night. 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. They were then taken to an undisclosed lockup for their own protection, and it was not immediately clear whether they had legal representation.
The child was airlifted to a hospital in northeastern Brazil on 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 in the city 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 after a 240-mile (390-kilometer) flight to the hospital in the coastal city of Salvador that has a special heart unit.
Hospital spokeswoman Susy Moreno said an evaluation of when to perform surgery on the boy probably would not be finished until Friday. He was in an intensive care unit but was conscious, had undergone a battery of X-rays and was receiving antibiotics, a hospital statement said. While the boy was admitted with some internal bleeding, the blood was drained and he did not appear in imminent danger of more bleeding.
The boy's mother, a maid, took him to a hospital in Ibotirama, population about 25,000, on Dec. 10, saying he was complaining of pain.
After X-rays revealed the cause, the mother told police she didn't know how the needles got inside her son, whose name was not released because of his age.
Police and doctors concluded it would have been impossible for the boy to have ingested the needles -- which have been also been found in a lung, his left leg and spread throughout his abdomen.
Afro-Brazilian religions practiced in Brazil have no ceremonies, rituals or practices involving harm to people, said Nelson Inocencio, director of African-Brazilian studies at the University of Brasilia.
He worried that the incident could hurt the image of the religions, of which Candomble is the most popular, and concentrated most in Bahia state.
"African religions in Brazil suffer from prejudice and discrimination," he said. "What happened to this boy without a doubt could feed into the prejudice against Afro-Brazilian traditions."