Months before James Holmes allegedly opened fire in a packed movie theater, he began talking about killing and said he would do so “when his life was over,” according to new court documents.

Prosecutors allege Holmes, 24, turned to a classmate in March with his dark intentions and later began carrying out his plan — buying weapons and body armor — as his academic career in a competitive neuroscience graduate program collapsed around him.

By the time prosecutors say Holmes made threats to a professor June 12, he had already failed his oral board exam and bought the assault-style rifle he’s accused of using in the theater attack.

The new information came to light in a court document released Friday that lead prosecutor Karen Pearson filed in an attempt to obtain University of Colorado records.

“The defendant had conversations with a classmate about wanting to kill people in March 2012, and said that he would do so when his life was over,” wrote Pearson, chief deputy district attorney for the 18th Judicial District.

Holmes is accused of killing 12 people and injuring 58 others during a shooting rampage July 20 at a midnight showing of “The Dark Knight Rises” at the Century Aurora 16.

He faces 24 charges of first-degree murder and 116 counts of attempted murder in the case.

The prosecution is casting Holmes as a disappointed student who launched a revenge plot after failing at his studies.

Pearson told Chief Judge William Sylvester in court Thursday that in the weeks before the shooting, Holmes failed his exam, was asked not to return to a lab he worked in and was encouraged by a professor to find another course of study.

The defense has said its client is mentally ill, without elaborating on the nature of his disease.

Public defender Daniel King said in a Thursday court hearing that he “would question the validity” of some of the prosecution’s assertions.

The timing of Holmes’ alleged conversations with his classmate four months before the shooting could bolster either side if they are admitted into evidence, said former Denver District Court Judge Christina Habas, now a plaintiff’s attorney with Keating Wagner.

“The prosecution would say it wasn’t a psychotic episode. It was a plan, a depraved plan,” Habas said. “The defense could say he’s been laboring under this delusion for a very long time.”

In the filing unsealed Friday, Pearson also repeated a previous claim that Holmes was kicked off campus after he made threats to a professor.

Psychiatry professor Lynne Fenton was treating Holmes before he left the university, although she’s not named in Pearson’s filing.

“After he was denied access to the University of Colorado Denver’s Anschutz campus, he began a detailed and complex plan to obtain firearms, ammunition, a tear-gas grenade, body armor, a gas mask and a ballistic helmet, which were used in the commission of the murders and attempted murders,” Pearson wrote.

CU spokeswoman Jacque Montgomery reiterated Friday that Holmes was never banned from campus, but she declined to say whether his access was limited in some other way.

“These legal processes will ultimately present the full history of James Holmes’ interactions with the University of Colorado, its educators and its medical providers,” Montgomery wrote in a statement citing a gag order by Sylvester that limits the information CU can provide.

Sources have said Fenton alerted a team of academic officials, dubbed the BETA team, who deal with threats on campus. Campus police were also warned about Holmes, according to Pearson.

Jessica Fender: 303-954-1244, jfender@denverpost.com or twitter.com/oh_fender