A man pointed a pistol at a police officer before being involved in a four hour armed siege, Lincoln Crown Court was told.
Gavin Crane pointed the imitation Colt 45 pistol straight at the officer who was called to a flat after Crane's estranged wife Catherine activated a panic alarm inside her home.
Edna Leonard, prosecuting, said the weapon was a BB gun which Crane had previously fired inside the property shattering a photograph of Catherine.
She said: "The panic button was responded to by two police officers. They arrived and went to the flat.
"They were allowed entry to the block. When they went down the landing they could see the door to the flat was open."
She said that once inside the officers tried to enter the room where Crane was but found their way blocked.
"It was then opened by this defendant. He had his right arm raised in front of him and pointed a hand gun straight at the police officer. It looked like a Colt 45 but was in fact a BB gun.
"The defendant was shouting to the police to back off and slammed the sitting room door shut. The officers retreated down the hallway but remained on the landing.
"Two or three minutes later the defendant opened the door and walked down the hallway. Again he had the gun.
"Again he had it in front of him pointing it at the officers."
The two officers then retreated from the building and firearms officers were called to the scene.
A siege followed with Catherine Crane and a small boy trapped inside the flat.
Crane later allowed the boy to be released but his estranged wife was held until just before 11pm when he walked out and was tasered by officers.
Later he told officers that he had little recollection of the incident. He said he could recall having the gun at one point but could not remember why.
Gavin Crane ,27, pleaded guilty to possession of an imitation firearm with intent to cause fear of violence as a result of the incident in Rayment House flats, Lincoln, on 26 June.
Crane , of no fixed address, also admitted charges of false imprisonment and making a threat to kill arising out of the same incident.
He was jailed for three years and four months.
Recorder Simon Medland QC also imposed a 10 year restraining order banning Crane from contacting his estranged wife or from visiting her workplace.
The Recorder told him "You behaved in an unpredictable and frightening and very dangerous way. This was a very realistic imitation firearm. It would have been a terrifying thing to see."
David Stanton, defending, said Crane had been having difficulties with his personal life and had suffered from mental health problems.
He said Crane had previously made attempts to take his own life as a result of his problems.