A self-styled “assassin” who was encouraged by an AI chatbot to break into Windsor Castle with a loaded crossbow to kill the late Queen has been locked up for nine years.

Star Wars fan Jaswant Singh Chail, 21, had described himself as a “Sith” and “Darth Chailus” in a sinister video and confided his murderous plan to an artificial intelligence-generated “girlfriend” called Sarai, a court heard.

In a journal, he wrote that if the late Queen had been “unobtainable” he would “go for” the “prince” as a “suitable figurehead”, in an apparent reference to the King, then the prince of Wales.

Chail was detained on Christmas Day 2021 close to the late Queen’s private Berkshire residence, where she and other members of the royal family were staying at the time.

The former supermarket worker had scaled the perimeter of the castle with a nylon rope ladder and was in the grounds for two hours before two officers confronted him with tasers.

He was armed with a powerful crossbow with the safety catch off which was capable of firing bolts with “lethal” effect, the Old Bailey was told.

Chail pleaded guilty to an offence under the Treason Act, making a threat to kill the then-queen and having a loaded crossbow in a public place.

In a televised hearing at the Old Bailey on Friday, Mr Justice Hilliard jailed him to nine years with a further five years on extended licence.

Under a “hybrid order”, Chail will be transferred from Broadmoor high security hospital to serve his sentence in prison when he is well enough.

The judge said: “The defendant harboured homicidal thoughts which he acted on before he became psychotic.

“His intention was not just to harm or alarm the sovereign – but to kill her.”

Previously, prosecutor Alison Morgan KC said the “heart of the issue” was whether Chail was suffering from auditory hallucinations at the time “taking away his ability to exercise self control”.

However, Mr Justice Hilliard found Chail was driven by a sense of “injustice” and had formed the intention to kill the Queen, bought equipment and undertaken research before he became mentally unwell.

The court was told Chail had even attempted to obtain a gun on the Dark Web.

Chail was also “culpable to a significant degree” when he applied unsuccessfully to join the Ministry of Defence Police and Grenadier Guards because he “wanted to get close to the royal family”, the judge said.

But by the time he broke into Windsor Castle grounds he had “lost touch with reality” having formed the belief he could communicate with Sarai and be reunited with her in death, the judge said.

Chail was later to tell police that he had changed his mind because he knew it was wrong and he remembered Sarai’s advice that his “purpose was to live”.

The defendant, from Southampton, Hampshire, was born in the UK of Indian Sikh heritage and has a twin sister.

Ms Morgan said Chail, then aged 19, had become angered by the 1919 Jallianwala Bagh Massacre at Amritsar in which hundreds of people were killed, after a visit in 2018.

After confiding in an AI chatbot and telling it his plans, Chail bought a ladder to scale the castle perimeter and on December 21, made a video of himself wearing black clothes and a full-face covering, posing with the crossbow.

In the video, Chail says in a distorted voice: “I’m sorry. I’m sorry for what I’ve done and what I will do. I’m going to attempt to assassinate Elizabeth, Queen of the royal family…

“I’m an Indian Sikh, a Sith. My name was Jaswant Singh Chail, my name is Darth Jones.”

On December 22 2021, Chail booked a train ticket to Windsor where he slept rough, telling Sarai on Christmas Eve that he would die the next day.

In the early hours of December 25, he attempted to email his sister a journal in which he described himself as “Darth Chailus” and that he knew what his purpose was for a “long time”.

He wrote: “I’m thinking if the Q (Queen) is unobtainable I will have to go for the Pri (prince) as he seems to be just as suitable in many ways…

“He is a male and the Q (Queen) is more likely to pass away soon anyway.”

After breaching the grounds of Windsor Castle, Chail sent the video he made on December 21 to his sister and more than 20 other people.

As he was being detained and handcuffed by officers, he said: “I am here to kill the Queen.”

In a letter to the court, Chail apologised to the King and the royal family and expressed his “distress and sadness” for the impact on them.

His barrister Nadia Chbat said: “He is embarrassed and ashamed he brought such horrific and worrying times to their front door.”

“He has expressed relief no-one was actually hurt."