A man allegedly caught with a samurai sword outside Buckingham Palace said the Queen was the enemy "that Allah tells us to fight", a court has heard.
Mohiussunnath Chowdhury, 27, from Luton, denies preparing acts of terrorism on 25 August last year, claiming he only wanted to get killed.
He shouted "Allahu Akbar" ("God is the greatest") as he was arrested, jurors at London's Old Bailey were told.
In a suicide note, he allegedly said the Queen will "be in the hellfire".
The court also heard how a potential sat-nav error led the defendant to a pub called the Windsor Castle, instead of one of the Queen's residences, earlier on the evening of his arrest.
'Kill them without mercy'
Uber driver Mr Chowdhury, of Kirkwood Road, Luton, had searched the internet for Islamic State group beheadings and Jihadi John, jurors were told.
On the day of his arrest, Mr Chowdhury sent a suicide note to his sister and changed his social media profile picture to a green bird, in reference to becoming a martyr, jurors were told.
"The Queen and her soldiers will all be in the hellfire they go to war with Muslims around the world and kill them without any mercy," he allegedly wrote to his sister.
Opening the trial, prosecutor Tim Cray recalled how shortly before 20:30 BST on Friday 25 August, Mr Chowdhury was driving outside Buckingham Palace in central London.
On the other side of the road was a marked police van.
"As the defendant got up to where the police van was coming towards him, he swerved his car through the traffic cones designed to keep the two lanes of traffic apart," Mr Cray said.
Two officers got out to investigate, thinking the driver was drunk or on drugs, he added.
Mr Chowdhury then allegedly reached for what turned out to be a 42in (1.06m) sword - which was shown to the jury.
"There was a short, desperate struggle with the officers trying to get the sword off the defendant while he is punching at them and they are punching at him," Mr Cray told the court.
PC Ian Midgley suffered a cut to the palm of his hand and Sgt Gavin Hutt cut his hand, before the officers used CS gas to disarm the accused.
Giving evidence, Sgt Hutt told jurors: "I feared for my own life, my colleagues and members of the public."
He said the situation was "very bad" and the "penny dropped that this was happening outside Buckingham Palace".
"It was just very surreal. I did not think it was happening to me. I realised it was a sword. I was saying, 'Get the knife off him'," he added.
The trial continues.