In a deal struck with prosecutors, a former Simi Valley teacher pleaded guilty Thursday to having a sexual relationship with a male student at the elementary school where she worked for eight years, officials said.

Malia Brooks, 32, pleaded guilty to three counts of committing a lewd act with a child under 14, and admitted to the special enhancement of substantial sexual conduct, according to court documents. Brooks had been accused of having an inappropriate relationship with an unidentified boy at Garden Grove Impact Academy, where she'd taught sixth grade since September 2004.

Brooks remained jailed on $2 million bail.

The plea deal averts a trial and the possibility that the young victim would have to testify, said Ventura County prosecutor Erin Meister said.

"It's always taken into consideration how a trial would affect the victim's thoughts and feelings," she said. "It's always a success when we don't have to put the children through a trial."

Brooks had pleaded not guilty Wednesday to the original charges that included one count of committing a lewd act, one count of oral copulation and three counts of sexual penetration. She faced 16 years in prison if she'd been convicted of those charges.

Under the plea bargain, Brooks faces 12 years behind bars when she is sentenced Aug. 23. However, Judge Kevin McGee indicated during Thursday's hearing that he'll sentence the defendant to just six years, Meister said.

Defense attorney Ron Bamieh said Brooks developed a relationship with the boy during a "manic episode" triggered by memories of being abused as a teenager while living in the Sudan with her missionary parents.

"For 31 years, she was a pillar of the community in terms of being a working mom, a mom who contributes to the community," Bamieh said. "Then she does this, which is way off the course. It's totally naive to think this just happened out of the blue."

Bamieh said Brooks, a married mother of two, wanted to bring an quick resolution to the case.

"She was concerned that there would be irreparable hurt to the child, as she was hurt," Bamieh said.

Brooks had been accused of having sexual contact with the unidentified boy sometime between Jan. 15 and Feb. 16. School officials put her on administrative leave on Feb. 21, after getting a report of suspected inappropriate behavior. They also notified police, who opened an investigation that led to her arrest on June 11.

She resigned her teaching post on June 5 as the Simi Valley Unified School District was taking steps to fire her. Her state teaching credential has been suspended but will be revoked as a result of her guilty plea.