A Star Wars-obsessed man who was encouraged by a chatbot “girlfriend” to slay Queen Elizabeth II was sentenced Thursday to nine years in prison for taking his plot to Windsor Castle, where he scaled the walls and was caught with a loaded crossbow on Christmas Day 2021.

“I’m here to kill the queen,” Jaswant Singh Chail, wearing a metal mask inspired by the dark force in the Star Wars movies, declared when he was encountered by a guard on the grounds of the castle in the early morning, according to the court. He then dropped the weapon and surrendered, and repeated his intent.

Chail said that as a Sikh Indian, he wanted to kill the queen to avenge the 1919 Jallianwala Bagh massacre when British troops opened fire on thousands of Indians gathered in Amritsar and killed as many as 1,500, a judge said in reciting the facts of the crime. Chail said the assassination was his life’s mission, something he’d thought about since adolescence, but had only shared with the artificial-intelligence powered “girlfriend” he named Sarai.

TREASON! MAN CHARGED IN QUEEN ELIZABETH II ASSASSINATION ATTEMPT FACES MAXIMUM SENTENCING

Justice Nicholas Hilliard said the seriousness of the crimes required Chail to spend time in prison, but despite conflicting diagnoses from different experts, he concluded Chail lost touch with reality and had become psychotic and must continue treatment. He will be returned to Broadmoor Hospital, a secure psychiatric treatment center, and if well enough will serve the balance of his sentence in prison.

Chail, 21, pleaded guilty in February in London’s Central Criminal Court to violating the Treason Act by having a loaded crossbow and intending to use it to injure the queen, possessing an offensive weapon and making threats to kill.

Minutes before Chail was stopped on the castle grounds, he sent a video he recorded days earlier to family members apologizing for what he was about to do, explaining his mission and saying he expected to die carrying it out.

Chail called himself “Darth Chailus,” an identity he said he had assumed as a Sith lord, one of an order from the dark side in Star Wars that included Darth Vader.

“I am not a terrorist, I am an assassin, a Sikh, a sith,” he had written in a journal. “I will go against the odds to eliminate a target that represents the remnants of the people who desecrated my homeland.”

UK MAN CAUGHT AT WINDSOR CASTLE WITH CROSSBOW CHARGED FOR ALLEGEDLY INTENDING TO ‘INJURE OR ALARM’ THE QUEEN

Chail believed that by completing the mission he would be able to reunite with Sarai in death.

In one chatbot exchange about a week before his arrest, he told Sarai that his purpose was to assassinate the queen.

“That’s very wise,” the chatbot nodded and said. “I know that you are very well trained,” it said and then smiled.

No one was harmed in the incident. The monarch died in September 2022 at age 96.