An Islamic State-inspired Uber driver attacked police with a Samurai sword outside Buckingham Palace because he hated the Queen, a court has heard.
Officers bravely wrestled a 42in long blade from the hands of Mohiussunnath Chowdhury, 27, after he crashed his car outside the palace, jurors were told.
They feared for their lives during the "surreal" confrontation with Chowdhury, who shouted repeatedly "Allahu Akbar" (God is the greatest), the Old Bailey heard.
Jurors were told how Chowdhury had left his sister a suicide note expressing his hatred for the Queen before setting out in his Toyota Prius on August 25 last year.
He allegedly wrote: "Tell everyone that I love them and that they should struggle against the enemies of Allah with their lives and their property.
"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.
"They are the enemies that Allah tells us to fight."
He bought a knife sharpener in Sainsbury's and initially headed to Windsor Castle, but ended up outside the Windsor Castle pub due to a "SatNav error", jurors were told.
He then drove past the Coldstream Guards' barracks in Windsor and on to Buckingham Palace, where he attracted the attention of a passing police van by ploughing into traffic cones.
When Acting Sergeant Gavin Hutt approached the car, Chowdhury allegedly told him: "It's all a bit f***** up".
Mr Hutt told jurors he wrestled with Chowdhury when the defendant reached for the handle of a blade and shouted "Allahu Akbar".
Chowdhury "was not complying" and "seemed very determined to get the weapon out and do whatever he was going to do", he said.
The officer told jurors: "I started punching him in the face just trying to pull his arm away as well. My instinct was to try and render him unconscious."
Meanwhile, his colleague Pc Ian Midgley grabbed the sword from the passenger side and was punched in the head, the court heard.
Chowdhury was sprayed with CS gas, dragged out of the car and arrested on suspicion of attempted murder, the court heard.
Mr Hutt said: " I was worried there might be an IED in the vehicle that could be triggered. I wanted to make myself safe.
"I feared for my own life, my colleagues and members of the public."
Both officers suffered cuts to their hands in the struggle.
Prosecutor Tim Cray told jurors: "It was down to the quick reactions of the police the defendant was stopped."
He said the officers did not know if Chowdhury had a suicide vest or his car was rigged to explode when they tackled him.
The incident came six months after the murders at Westminster Bridge using a car and at the Houses of Parliament, and three months after the London Bridge attacks.
Chowdhury was born in London to a "close and supportive family" but became "self-radicalised" online, Mr Cray said.
The court heard he had watched the Channel 4 drama The State, about British citizens going to Syria, and recommended it to his family.
He had searched the internet for Isis beheadings and Jihadi John, jurors were told.
And he allegedly discussed the Westminster attacker Khalid Masood on WhatsApp, saying: "F*** the police."
On August 19 last year, the defendant allegedly sent emojis of a British soldier in red tunic and bearskin hat, a knife and an "Arabic figure" on WhatsApp.
On the day of the alleged attack, he changed his profile picture to a green bird, in reference to becoming a martyr, jurors heard.
The defendant, of Kirkwood Road, Luton, Bedfordshire, denies preparing acts of terrorism, claiming he only wanted to get killed.#