A mentally ill California man pleaded guilty on Monday to four counts of murder in a deadly spree targeting sleeping homeless men, four of whom were stabbed to death with rail spikes and two were set on fire.

Jon David Guerrero, 42, wore a surgical mask on his face due to an unspecified illness as he agreed to be sentenced May 1 to four consecutive life terms in prison without the possibility of parole and an additional 143 years to life in prison.

Guerrero, who was scheduled to go to trial in June, also pleaded guilty to four counts of attempted murder, five counts of assault with a deadly weapon and two counts of arson for setting fire to two of four victims who died.

The charges involved 12 men and one woman who were attacked over six months between February and July 2016, the San Diego Union-Tribune reported.

Jon David Guerrero, who terrorized the homeless community in San Diego in 2016 when he drove railroad spikes into the heads of some of his victims, pleaded guilty on Monday to 15 charges, including four counts of murder. Guerrero wore a surgical mask due to an illness

Police inspect the scene where Guerrero's fifth and final victim, Michael Papadelis, was attacked with rail spikes driven into his eyes on July 15, 2016

Court records show Guerrero is diagnosed with schizophrenia and has a history of arrests and mental competency hearings, including one judge's order that sent him to a state hospital for treatment.

The only clue to a motive for the assaults came from Guerrero's first victim, who survived a knifing and asked his attacker, 'Why did you do this to me?'

'Because you're a bum,' Guerrero replied, according to the victim's statements cited by the Union-Tribune.

One assault victim who survived, Michael Papadelis, attended the Monday hearing and afterward said of Guerrero's guilty plea, 'I think he did the right thing.'

Guerrero was arrested just two hours after attacking his final victim on July 15, 2016 (pictured at the time of his arrest)

Arresting officers found rail spikes and a mallet inside Guerrero's backpack

'I've been homeless. I know there are a lot of mentally ill on the streets. I don't hate Jon,' Papadelis, 58, who was left blind in one eye, told the newspaper.

In 2018, Guerrero was declared mentally competent - meaning he could understand the charges filed against him and assist in his defense - and the criminal case against him went forward.

'It’s a huge, huge relief to have finality to this,' Deputy District Attorney Makenzie Harvey said after the hearing Monday. 'I think it’s a very, very great thing to the victims and their families.'

Guerrero, who is from San Diego's affluent Coronado district, began his spree on February 8, 2016, when he stabbed a man sleeping on a sidewalk. That victim survived.

After a months-long hiatus, Guerrero resumed his attacks on the city's homeless population on July 3, when he doused Angelo DeNardo, 53, with gasoline and set him on fire, killing him.

The next day, 41-year-old Shawn Mitchell Longley was found stabbed to death with a railroad spike at a park in Ocean Beach.

A witness told the Daily Beast Longley's eyes and face had been spiked with a sharp object and his skull crushed by a heavy rock.

Guerrero attacked Manuel Nunez Mason, 61, the same day. Mason survived but was rendered blind after a railroad spike was driven into his sinus cavity.

On July 6, Dionicio Derek Vahidy, 23, was mortally injured when his attacker dropped a burning towel on his face while he slept in downtown San Diego. The victim died in a hospital four days later.

Guerrero attacked 83-year-old Molly Simmons on July 16, 2016. The woman was struck on the head on her way to volunteer at a YMCA, and she died of her injuries three weeks later. Detectives said the woman was not homeless and lived with her husband.

Guerrero attacked his fifth and final victim, Michael Papadelis, on July 15.

Authorities discovered Papdelis with 'significant trauma' to his upper body and a railroad spike lying next to him as he called for help.

Guerrero, pictured leaving court in 2017, was diagnosed with schizophrenia but was declared mentally fit to stand trial in 2018

Police found Guerrero riding his bike less than two hours later. Three railroad spikes, a mallet and two of the victims' identification were inside his backpack.

More railroad spikes and ties, as well as a bucket that contained rocks, were later found in his apartment at a 'supportive housing' project for the formerly homeless and individuals with special needs.

Guerrero was diagnosed with schizophrenia at the age of 22 and at one point received monthly injections of an anti-psychotic drug.

He has an extensive history of criminal cases in the city that date 10 years, from 1999 to 2009, as well as mental health cases filed in 2008, 2009 and 2011.

Guerrero's mother illuminated his mental health issues after he pleaded guilty in 2004 to burglary, grand theft auto and marijuana possession.

In letters to the court, Katherine Guerrero revealed her son didn't do well on probation because he lacked 'hearing and speaking ability'.

She also said one of his symptoms in the past had been to 'insert foreign objects into his body orifices', according to the Los Angeles Times.

Guerrero was ruled not mentally competent after he was arrested in 2009 and pleaded guilty to stealing a homeless woman's bike after repeatedly knocking her down.

He was admitted to Patton State Hospital after violating his probation.

Guerrero's attorney then argued for a lesser sentence, writing that his client heard voices when his medication wears off but that he could 'lead a normal, productive and crime-free life' with the right drugs.