A British man accused in the fatal stabbing of a hair stylist in Chicago that a prosecutor said was driven by a sexual fantasy has agreed to plead guilty in a US court and testify against his American co-defendant in the killing.

Andrew Warren, 58, formerly an employee at Oxford University, on Monday admitted first-degree murder and will give evidence against his accused fellow killer, a former Northwestern University professor, in exchange for a 45-year prison sentence.

Warren’s written plea agreement came almost two years after 26-year-old Trenton James Cornell-Duranleau’s body was discovered in July 2017, riddled with stab wounds in an apartment in Chicago.

Prosecutors later said the young man had been stabbed 70 times and with such brutality that he was nearly decapitated. His throat was slit and pulmonary artery torn.

The discovery prompted a nationwide hunt for Warren and the former professor, Wyndham Lathem, who lived in the apartment and was eventually identified as Cornell-Duranleau’s boyfriend.

Wyndham Lathem arrives at a Chicago police station in 2017. Photograph: Jim Young/AP

Lathem and Warren, who at that point still worked at Oxford University, surrendered to authorities in California just days later.

Prosecutors spelled out how Warren and Lathem met in an online chatroom where they hatched a plot to kill Cornell-Duranleau and then themselves.

Natosha Toller, an assistant Cook county state’s attorney, in Illinois, described the plan as a sexual fantasy.

But after they killed Lathem’s lover, they lost their nerve and fled Chicago on a strange road trip to California that included a stop at a public library in which they made large donations in Cornell-Duranleau’s name.

The two, who both initially pleaded not guilty to first-degree murder, are being held without bond in jail in Chicago.

No trial date has been set for Lathem, once a respected associate professor of microbiology-immunology at Northwestern, in Illinois. He is scheduled to return to court next week.

About half a dozen relatives and supporters of Cornell-Duranleau attended the hearing for the 58-year-old Warren on Monday but they left the courthouse without speaking to the media.