A man shot by police after trying to kill officers with a crossbow has been jailed for nine years.

Jamie Thomson fired the crossbow, threw knives and launched fireworks during the seven-hour stand-off at his flat in Kilbirnie, North Ayrshire.

The 25-year-old later said he wanted to write a letter in "favour" of the police marksman who shot him in the arm.

Thomson last month pleaded guilty to attempted murder when he appeared at the High Court in Glasgow.

The court heard the stand-off began in Bankfaulds Avenue on March 12 this year and when police arrived, they saw a topless Thomson stomping around his home with a number of large knives on the window ledge.

He initially hurled one of the weapons at police, before he shouted: "I'll chop your heads off. Bring it on. I will kill you."

Thomson also smashed windows then launched fireworks from his home as back-up was called for.

He returned to court on Tuesday for sentencing and was handed a nine-year jail term by judge Lady Scott.

She told him: "This was a highly dangerous and protracted course of violence directed at police officers acting in the course of their duty in seeking to prevent this disturbance and latterly to protect life.

"Your actions in throwing fireworks and shreds of glass directly at them, followed by shooting at them using the crossbow, placed the individual police officers in grave danger.

"By your plea you have accepted that you had a wicked intention to kill the police involved or were wickedly reckless as to whether that was the result."

The court previously heard "a full firearms operation", including three armed response vehicles and police negotiators, arrived in a bid to subdue him.

Thomson called a former partner at one stage to tell her he was "getting ready" to be arrested or "taken from his home dead".

He continued to throw items at officers including glasses, cans, bottles, crockery, ice cream tubs and a games console.

Thomson barricaded himself in his property before firing bolts from his crossbow at several officers. He was eventually shot in the arm at around 12.15pm, before being arrested and then treated for the wound.

After being arrested, Thomson said he wanted to write a letter in "favour" of the officer who shot him and said there was "no need" for an investigation.

Lady Scott said: "The very serious nature of this conduct requires me to impose a very substantial prison sentence.

"Whilst you have been seen by a number of psychiatrists since you were a teenager and at times treated with anti-psychotic drugs, the psychiatric report before me suggests you do not have any mental disorder, that you are functioning well and there is no basis for reducing your responsibility for your actions here. You were heavily intoxicated at the time."

Chief superintendent Nelson Telfer said: "Police Scotland has specialist firearms resources to provide a swift and effective response to firearms incidents or where there is a threat to life risk.

"Officers attended the incident in Kilbirnie as the accused had barricaded himself in a property for several hours and was behaving in a threatening manner.

"After he discharged a crossbow aimed at officers, he was shot by an authorised firearms officer from the attending armed policing unit to disable him and was taken to hospital for treatment."

He added: "If lives of members of the public or police officers are at risk in such high-threat situations, then it is a priority for police to contain the scene and make it safe in line whilst following agreed procedures.

"These type of spontaneous firearms incidents are rare but underline the important role that armed policing has in protecting the public and our communities in Scotland."