The woman's tongue was left bleeding and her face swelled after Kian Watson put her in headlock with such force that she began to lose consciousness, Leeds Crown Court was told.
He was given a 20-month sentence, suspended for two years, but was told by Judge Simon Phillips QC he was very fortunate to stay out of jail.
The judge said: "It's a very troubling case. You have come within a hair's breadth.
"Just by the narrowest of margins I can pull back from imposing and immediate custodial sentence."
Oliver Connor, prosecuting, said that warehouse operative Watson, 19, had gone to his ex partner's home in Wakefield on November 22 last year to collect his belongings after their relationship ended on good terms.
With the pair both on the bed, and the victim on her laptop, Watson tried to get her attention by putting his arm around her neck.
She told him to get off, and he did. He did it a second time and took his arm away again when she told him to.
However, on the third attempt he clamped his arms around her neck in a headlock grip and refused to stop when she asked him.
She told him she could not breathe but he maintained his grip.
They both fell onto the floor and she tried to grab her phone but he put it out of reach. She also tried to scratch his face to fend him off.
She later told police her vision began to fade and was losing consciousness before he let go.
He then kept apologising as she called 999. She was taken to hospital.
Watson was arrested and initially gave a no-comment interview, but then told officers he had blacked out and could not remember what happened.
Watson, of Princess Close, Chickenley, Dewsbury, pleaded guilty to assault occasioning actual bodily harm. He has no previous convictions.
Holly Clegg, mitigating, said that Watson had been struggling with mental health issues for a number of years and had turned to illegal drugs including cocaine and MDMA.
She said: "He takes full responsibility for his actions.
"He never set out to hurt her and he can't apologise enough. He has now stopped using drugs and alcohol.
"He does appreciate how serious his actions are."
She said that Watson was now in a new relationship.
Judge Phillips said: "This was a serious, sustained strangulation.
"She suffered serious psychological harm and continues to do so.
"You may have moved on in life but she is left no longer feeling safe, suffering flashbacks and feeling isolated all because of the violent way you mistreated her."
Watson was ordered to do 180 hours of unpaid work and to pay £1,000 compensation to the victim.
He was also made the subject of a restraining order banning him from contacting her.