A Dublin man struck a garda's wife in the face in a "nasty, vicious attack" after he tried to follow her into her apartment block as she returned home from a Christmas night out.
Drug addict Shane Balfe (31) was seen "stalking" the woman as she got her keys out, then slapped her across the face when she confronted him.
Her husband, a detective garda, heard her screams and jumped out of bed to come to her assistance, then alerted officers on duty nearby.
Jailing Balfe for 15 months, Judge Michael Walsh said the attack had an "appalling" effect on the victim, who had since moved away.
The accused, from Basin Grove, Basin Lane in the south inner city, pleaded guilty to assault and other offences.
Dublin District Court heard gardai were on duty at Bonham Street, Dublin 8 at 4.30am on December 20, 2015 when the victim's partner, an off-duty garda, alerted them to the incident.
He told them his wife was distressed and required assistance. She said Balfe had slapped her across the face minutes earlier, explaining she had been entering her apartment block when she noticed him trying to walk in behind her.
She had an argument and he struck her across the face.
Judge Walsh referred to a victim impact statement, saying the woman had been out with friends and when she walked to the entrance of her apartment complex and took her key out of her pocket, she was accosted by Balfe, who assaulted her.
She screamed for help and fortunately, her husband heard her cries, jumped out of bed and ran down to her aid.
The victim had collapsed in fear and distress and Balfe was abusive and threatening. CCTV showed him "stalking" the victim, following her along the street, Judge Walsh said.
The assault had had a "devastating" effect on her personal life and she had to move from her home, where she had lived for eight years.
"It illustrates how vulnerable members of society are at risk from certain individuals who, it seems to me, have lost all sense of decency and act in a manner which wreaks havoc and causes harm and upset to ordinary, law-abiding members of society," Judge Walsh said.
It was a "very nasty, vicious and vulgar attack" and Balfe was lucky he was not facing more serious charges, he said.
Balfe also admitted a series of other offences, including shoplifting cider and selling heroin to an undercover garda.
In another incident, he was with a group of men who broke into a business premises in the north city centre. When gardai found them allegedly taking drugs inside, Balfe became abusive and was arrested.
On May 13, gardai were chasing a suspected drug dealer on foot on O'Connell Bridge when Balfe got involved, following the pursuing gardai and verbally abusing and threatening them.
They told him to leave the area and he threw an open container of cider on to the patrol car window. He was chased and had to be brought to the ground.
Balfe had 60 previous convictions.
Explaining why he had failed to appear in court previously, his lawyer explained Balfe was "under threat from a particular gang and he doesn't want their name mentioned in court".
Balfe had had serious addiction problems for most of his life and most of his offending arose from drinking too much or taking drugs, he said.
He suffered tragedies in his life and took a "turn for the worst" after his mother died.
Balfe acknowledged he had "damaged people's lives", but Balfe himself was a "damaged individual" through addiction, his lawyer said.
Judge Walsh imposed a series of sentences totalling 15 months.