Monifa Sanford, one of two Montgomery County women accused of killing two young children during what they believed was an exorcism, was ruled criminally insane on Friday and was committed to a maximum-security psychiatric hospital.

Sanford, 22, who had called herself a “demon assassin,” pleaded guilty to two counts of first-degree murder and two counts of attempted first-degree murder. Sanford will stay at Maryland’s Clifton T. Perkins Hospital Center at least until it is determined that she no longer poses a danger to the public. She could very well be at Perkins for the rest of her life.

“This case represents a horrible descent into the depths of mental illness,” said Sanford’s attorney, David Felsen. “Monifa believed Satan was going to kill the children and she needed to kill the children to save their souls.”

Friday’s hearing revealed the most detailed account so far of the horrifying violence that erupted inside a townhouse in Germantown, about 20 miles north of the District. At the time, Sanford was living with Zakieya Avery, then 28, and Avery’s four young children.

In the early morning hours of Jan. 17, 2014, the women became convinced that demons had invaded the children’s bodies, prosecutor Peter Feeney said in Montgomery County Circuit Court.

Monifa Sanford (Montgomery County Police/EUROPEAN PRESSPHOTO AGENCY)

First, they attacked Norell, 18 months old, Feeney said. Avery held him down and stabbed him repeatedly with a serrated paring knife, he said, while Sanford stroked the boy’s face to try to calm him. The two women then attacked Zyana, 2½ years old, who was stabbed at least 13 times.

At some point, Feeney said, 8-year-old Martello walked into the younger children’s room, began to cry and yelled for his mother to stop. He, too, was attacked — stabbed by his mother and then stomped. The two women also went after Taniya, 5, Feeney said, stabbing her and telling her to “confess.” Taniya managed to crawl into another room and curl up in a bed, moaning in pain and suffering from a punctured lung.

Norell and Zyana died.

Martin Harris, the children’s father, was among those in court. In an interview, he said that Taniya and Martello have scars on their chests but have recovered physically.

In the months after the attacks, Taniya would still try to spot Norell and Zyana. “I know she was looking around for her playmates,” Harris said.

Taniya and Martello are working hard in school, Harris said, and aren’t as withdrawn as he feared they would be: “My kids are really, really resilient.”

During the hearing, Feeney spoke about Sanford’s motives.

“Detectives asked Sanford how she felt about what she did to the children,” Feeney said. “Sanford said she was ‘happy the children are in heaven, but I miss them.’ ”

Sanford also told detectives that she had kept Satan from overtaking Norell and Zyana. “Now God has them,” she said, according to Feeney.

In Maryland, people can be found criminally insane if mental illness keeps them from understanding that they are committing a crime. In that context, the developments in Sanford’s case on Friday stand in contrast to the legal route underway in the case against Avery, the children’s mother. That is because last year, a state psychiatrist concluded that Sanford was legally insane at the time of the killings, but a different state psychiatrist concluded that Avery was legally sane. Avery’s attorney, Brian Shefferman, is questioning how this can be, given that the pair are alleged to have killed the children at the same time and for the same reasons.

Shefferman has been given additional time to enlist another doctor to evaluate Avery, who has a history of mental illness and had been committed to a mental-health facility before her children’s deaths, according to court records. As of now, her trial date is set for June 24.

Friday’s hearing offered insight into the state of mind of Avery and Sanford that morning a year ago.

Feeney told Circuit Judge Cheryl McCally that the prosecution’s account was based on detectives’ interviews with Sanford and Avery, medical reports and other evidence.

Feeney’s account to the judge follows:

Sanford and Avery met in February 2013 at a small church in Montgomery. At the time, Sanford was living with her father and taking classes at a community college in the county. Avery began to tell Sanford about demons and showed her YouTube videos that purported to depict them. In time, Sanford told Avery that she thought there were demons at Sanford’s father’s house and at the Giant grocery store where she worked. Avery suggested that Sanford quit her job and stay in Avery’s townhouse, and her friend agreed.

The women called themselves “demon assassins.” They began to isolate themselves from other adults. They stopped attending their church, which they thought had also been invaded by demons. Neither had a job, believing that God didn’t want them to. Avery received financial assistance from the state; Sanford had help from a relative.

In December 2013, the children’s paternal grandmother took them to Philadelphia to visit their father. When the children returned, the women went through toys the children had received as Christmas gifts and threw away those they believed were possessed.

By this time, the women also imagined that they had boyfriends, named “Dawntea” and “Troy.” And on the night of Jan. 16, 2014, Avery and Sanford planned to perform an exorcism on the men in the home. The women were concerned that demons might jump into the children, so the women took all four children outside — placing them in Avery’s blue Toyota — and returned to the townhouse.

It was about 32 degrees outside, and the car wasn’t running. A neighbor walked by the car, saw the children crying and knocked on Avery’s front door. Avery said they were all getting ready to leave. About 40 minutes later, the children were still in the car, and another neighbor knocked on the door. Sanford brought the children inside. This neighbor spoke on the phone with police, who came out and knocked on Avery’s door for about five minutes. They got no answer, saw lights turn off and called their department’s child-abuse section. The officers tried knocking again, still got no answer, called the county’s Child Protective Services agency and left.

Police officials have previously said their officers didn’t have probable cause to force their way into the townhouse. Nothing revealed Friday suggested that wasn’t the case.

Early in the morning of Jan. 17, 2014, Avery awakened Sanford, telling her that spirits had taken over the children. Avery told Sanford to get a Bible and put on the “armor of God.” They went to an upstairs bedroom where the two younger children were. Norell was crying. Avery told Sanford that demons were in him. Sanford thought she saw his eyes turn black.

“Avery picked up Norell, gripped her hands around her son’s neck and tried to choke him,” Feeney said.

The prosecutor added that Sanford thought she could pray the demon out of Norell by speaking in tongues and that Avery then told Sanford to get a knife.

Detectives believe that Avery cut and stabbed Norell at least eight times, injuring him as he held up his hands to try to defend himself.

Detectives think that Sanford choked the next oldest child, Zyana, unconscious. Detectives could never determine which woman stabbed Zyana but learned that some of her wounds were so deep that they passed though her chest and out her back.

After attacking the older children, the women tossed two bloody knives out an upstairs window onto the front yard, officials believe.

About 9:40 a.m., a neighbor called police, reporting a suspicious situation outside the townhouse — a Toyota with at least one door open and a knife that possibly had blood on it. She also said she’d heard noises from the townhouse the night before but thought it was just kids running and jumping around.

Officers arrived at the house, saw a set of keys in the back of the Toyota and grabbed them. They knocked on the townhouse’s door, got no answer and used a key to go inside.

Avery ran out a back door, taking Martello with her. Police caught up to her after she had placed Martello in a back seat but before she could get behind the wheel. Inside the house, the officers found the other children and Sanford.