A schizophrenic man launched an unprovoked knife attack on a train passenger after yelling "I want to kill all the Muslims", a court has heard.
Adrian Brown, 38, was said to be suffering a "severe psychotic episode" when he stabbed Muhammed Ali on a London Overground carriage on December 12 last year.
The intervention of other passengers on the train, which was travelling between Honor Oak Park and Forest Hill, south London, might have saved the victim's life, his trial at Southwark Crown Court heard.
Brown accepted he carried out the attack but pleaded not guilty to a charge of attempted murder on the grounds of insanity.
Prosecutor Alan Kent QC told the court: "The defendant was living in a hostel on the morning of December 12, he left that hostel armed with a knife - he was determined to find and kill Muslim men.
"He went to the train station at Honor Oak Park which isn't very far away from the hostel where he was living. He had with a knife which he took from the hostel.
"He walked up and down the train threatening passengers, threatening death to Muslims while looking for any Muslim men to stab and kill.
"He saw the victim, Mr Muhammed Ali, who was sitting on the train with his wife. The defendant approached Mr Ali who was sitting down and repeatedly stabbed him to his head and his body.
"Other passengers on this train came to Mr Ali's rescue and it would seem it was their bravery coupled with medical attention from a doctor and a nurse who happened to be on a train, that they may well have saved his life through their quick medical intervention."
Mr Ali suffered injuries to his head and torso, as well as a punctured lung.
Jurors at the trial of issues will consider whether Brown was insane at the time of the attack.
He is also accused of carrying a knife and assault by beating of Filipe Dias, who worked at the hostel, during an earlier incident, both of which are denied on the grounds of insanity.
The court heard Brown had become agitated over the absence of hot water and set upon Ms Dias, who had previously confiscated knives from him.
Mr Kent said: "He was unhappy about a problem there with the hot water system.
"But there was something much more serious going on in his head at that time because what he suddenly came out with is 'I'm going to destroy Isis, Isis are the problem'."
Ms Dias then came across his path and was grabbed by the throat and shouted at.
"As he left the defendant was heard to say: 'I'm going to kill some Muslims'."
When at the station he was heard saying "where are all the Muslims? I am going to kill all the Muslims" before holding a knife to the throat of another woman, who was unhurt.
He then spotted the victim, whose wife was wearing a hijab and a burka.
"He called him a 'f*****g Muslim' before attacking him with a knife, stabbing him repeatedly and repeatedly shouting 'f*****g Muslims' as he did so," Mr Kent said.
"He stabbed Mr Ali numerous times, the crown say, clearly in an attempt to kill him."
Brown, of Brockley Rise in south-east London, appeared via video link from Broadmoor Hospital during the hearing, wearing a brown tracksuit.
It was heard two psychiatrists had determined he was insane at the time of the attack.
"He is at Broadmoor Hospital where he is being treated," Mr Kent said.
"He has a very long history of paranoid schizophrenia - there is no doubt that when he carried out these offences he was suffering a very severe psychotic episode."
Jurors were told by Judge Deborah Taylor they could reach one of three verdicts: not guilty, not guilty by reason of insanity or guilty.
Brown's defence counsel has to prove "on the balance of probabilities" that he was insane at the time, the court heard.
His defence was called "highly unusual" by Mr Kent, who added: "But this is an unusual case."
CCTV was shown to the court of Brown walking down the train carriage moments before the attack and a commotion immediately afterwards.
Passengers could be seen scattering in panic as the violence unfolded.
Ms Dias then appeared before the court to describe her ordeal, saying Brown was "distressed" at the time he allegedly attacked her.
She said: "He was shouting and then he grabbed me by the neck, he pushed me against the wall and I just froze and did nothing, I tried to move my head and he just pushed my chin."
Another resident of the Honor Lea hostel, which specialises in working with people who suffer from mental health issues, intervened to free her and Brown left, the court heard.
Ms Dias added: "The last thing he said was 'I'm off to kill some Muslims' and then I had the impression that he had a knife."