A Georgia man — whose extraordinarily vulgar courtroom exchange with a judge was immortalized by the hit TV show “Rick and Morty” — has pleaded guilty but mentally ill to killing his cellmate.

Denver Fenton Allen, 33, pleaded guilty Monday after Judge Billy Sparks denied Allen’s motion that he killed Stephen Rudolph Nalley in self-defense after just five days in the Floyd County Jail, the Rome News-Tribune reports.

Allen — who suffers from delusions and schizophrenia, according to a state evaluation that still found him fit for trial — was sentenced to life in prison Monday, prompting him to threaten to kill people in the courtroom, including the assistant district attorney.

In June 2016, Allen made national headlines for an obscene, 11-minute exchange with Superior Court Judge Bryant Durham in which Allen threatened to kill the judge’s family and made repeated graphic sexual threats.

Allen claimed his court-appointed attorney had made unwanted sexual advances toward him and was inadequately prepared. Durham said he doubted those claims and recommended that Allen go to trial with the attorney rather than represent himself, prompting Allen’s incredibly crude tirade.

CLICK HERE TO READ MORE FROM THE NEW YORK POST