A paranoid schizophrenic accused of killing three elderly men was suffering delusions about rescuing a young woman from a gang of paedophiles at the time, a court has heard.
Alexander Lewis-Ranwell allegedly battered 80-year-old Anthony Payne with a hammer before bludgeoning to death 84-year-old twins Dick and Roger Carter with a shovel in Exeter in February.
At his trial at Exeter Crown Court, a psychiatrist told the jury that he believed on the "balance of probabilities" that the 28-year-old former scaffolder was insane at the time he killed the pensioners.
Dr John Sandford, who had been called by the defence to give evidence, said Lewis-Ranwell had described his actions as "a whirlwind of destruction" and that he acknowledged "he had no right to do what he did".
The psychiatrist added: "He knew he was entering someone's property and he knew when he was killing someone that he was going to be causing serious harm, but he didn't believe these people were completely innocent.
"He believed he was on some sort of quest. It's my opinion he was on a quest and that was a morally good thing to do."
The killings allegedly took place three hours apart on 10 February, at two houses just a mile-and-a-half away from each other.
Lewis-Ranwell had been arrested twice in the days before, the court was told.
He was initially detained on 8 February after an attempted burglary at a farm - but he was released from custody and taken to a homeless shelter at 3am on 9 February.
Later that morning, he was arrested again after attacking a different farmer with a saw. He was released on bail on 10 February after spending a day in police custody.
The attacks on the three elderly men began hours later, the court heard.
On 11 February, Lewis-Ranwell was arrested for a third time following an incident at a hotel in Exeter, and he was transferred to a psychiatric unit after concerns were raised for his mental health.
Detectives subsequently linked him to the deaths and he was arrested on suspicion of murder.
Dr Sandford said Lewis-Ranwell was a paranoid schizophrenic and was suffering from acute psychotic delusions and hallucinations - meaning his ability to exercise self-control was diminished.
The court heard that he believed a gang of paedophiles had taken a girl 25 years ago and she was being abused in a basement in Exeter.
Dr Sandford said Lewis-Ranwell saw a note Mr Payne had left on his front door and believed this was linked to the missing girl.
He added that when the defendant went into the building he saw knives, scissors and hammers that he thought had been used to torture the girl.
Dr Sandford said Lewis-Ranwell acknowledged killing Mr Payne, who he mistakenly believed "was a paedophile who was keeping this girl as a prisoner for 24 or 25 years".
The psychiatrist added: "He acknowledged he assaulted this man with a hammer and caused him serious harm and he acknowledged that he killed him."
Less than three hours later, Lewis-Ranwell allegedly attacked and killed the Carter brothers with a shovel after also wrongly believing they were paedophiles.
Lewis-Ranwell, from Croyde, north Devon, denies three charges of murder by reason of insanity.