A man who fired an illegal shotgun out of a window during a siege when police officers were outside has been jailed.
Daniel Hannam, from Gillingham, Dorset, was convicted of possessing a firearm with intent to endanger life.
Officers said they thought they were going to die when he fired the weapon from a house in Castle Cary, Somerset, on 23 January.
At Bristol Crown Court on Friday, a judge jailed 33-year-old Hannam for 24 years.
During a three-week trial, Hannam admitted shooting the weapon from an upstairs window at his former girlfriend's home in the early hours but claimed he was aiming into the air and not at police.
Two officers who were at the front door of the end-of-terrace property at the time returned fire.
Hannam later phoned 999 and told the operator: "I've just had a shoot-out with your police officers yeah, they've surrounded the house right now.
"There are two children and a woman inside this house, how do you want this to go down right now? That's what I want to know."
The judge, Mr Justice Soole, praised the officers' "quite remarkable courage".
"I simply wish to recognise the court's overwhelming admiration for the work they did that night and continue to do," he said.
Jurors unanimously acquitted Hannam of attempting to murder the officers.
He admitted charges including attempted kidnap, making use of a firearm with intent to resist arrest, possessing a firearm with intent to cause fear of violence, and attempted burglary.
Hannam was also sentenced for an armed robbery at a supermarket in Yeovil a week before the armed siege.
Det Ch Insp James Riccio, from Avon and Somerset Police, said: "He put an armed shotgun to the heads of two individuals. They've shown immense bravery."
One of the store workers said in an impact statement: "I truly believed he would use the gun on us. I have never seen a gun before and it was the most terrifying five minutes of my life."
The judge jailed Hannam for 24 years and imposed an extended period on licence of five years.
He crossed the threshold for "dangerousness" and it was "beyond doubt" he posed a "significant risk to the public", the judge said.
"You have a very bad record of offences of violence and your record shows an escalation of violence," he added.