Obsessed Alex Gray’s criminal campaign of abuse also involved contacting the British singer on social media, handing her offensive letters and a “romantic CD”, and accusing her of “stealing” lyrics he had written.
The 31-year-old, of Perth, showed no emotion as he was handed an indeterminate hospital order and restraining order for burglary and stalking at Harrow Crown Court, north London, on Friday.
Ms Allen was not present for the hour-long hearing, but a victim impact statement read before the judge said she was “left terrified for my and my children’s safety”, having been in the room when the defendant gained access to her flat.
She said the presence of another person with her at the time was likely to have scared him off.
Sentencing, Judge Martyn Barklem said Gray had told police he would “cut her with a knife”.
The judge said: “This was a terrifying experience for (Lily Allen), and it was extremely fortunate there was an adult male in the property who evicted Mr Gray from it.”