A Santa Cruz County judge ruled that a teenager charged with rape and murder in the slaying of an 8-year-old neighbor will be prosecuted as an adult — eliminating the possibility he could be released at age 23 if convicted as a minor, court officials said.

Adrian “A.J.” Gonzalez was 15 years old when he was charged with offenses including murder with the special circumstances of lying in wait, murder in the course of forcible rape, and kidnapping in the July 2015 death of Madyson “Maddy” Middleton.

Gonzalez, now 18, had spent years in juvenile hall but was immediately placed into adult custody Tuesday after Santa Cruz County Superior Court Judge John Salazar ruled the teenager would be tried as an adult, said Sue Huckins, a court spokeswoman.

With Tuesday’s decision, Gonzalez could face life in prison if convicted. He will now re-enter the court system, this time as an adult, with an arraignment scheduled for the end of November.

Throughout the juvenile transfer hearing, Santa Cruz County District Attorney Jeff Rosell argued the sophistication of the crime, as well as its “shocking and disturbing details,” warranted adult court.

Public Defender Larry Biggam, representing Gonzalez, said Wednesday he plans to appeal the ruling because his client had suffered years of childhood trauma, was responding well to treatment at juvenile hall and has been “a model inmate.”

“The kid needs more assessment and treatment,” Biggam said. “As a result of the judge’s ruling, he will now receive no treatment and will be exposed to a toxic adult prison environment.”

The transfer hearing spanned two months as Salazar listened to various experts testify on both the details of the crime and Gonzalez’ ability to be rehabilitated.

It was once up to prosecutors to decide whether juveniles would be tried as adults, but hearings like Gonzalez’s became mandatory in California with the passage of Proposition 57 in 2016, which left such decisions up to the discretion of judges.

Salazar reviewed a number of criteria outlined in the law when making the decision, including whether the minor can be rehabilitated, the defendant’s delinquent history, the success of attempts by the juvenile court to rehabilitate him and the circumstances and gravity of the case.

Authorities said Gonzalez used ice cream to lure Maddy to his apartment unit at the Tannery Arts Center. He is accused of raping her, stabbing her in the neck and dumping her in a recycling bin, where she died of positional asphyxiation.

Supporters outraged at the possibility Gonzalez would be tried as a juvenile sat in court throughout the trial. Maddy’s grandfather, Dan Middleton, started an online petition in July, seeking to have Gonzalez tried as an adult. The petition garnered 7,875 supporters.

Tuesday, Middleton posted an update with the subject line, “Victory!”

“It has been ruled that Adrian Gonzalez will be tried as an adult,” his post read. “Thank you for your support for the protection of our children.”

Jenna Lyons is a San Francisco Chronicle staff writer. Email: jlyons@sfchronicle.com

Twitter: @JennaJourno