A mentally ill stalker who left pop star Lily Allen "terrified" after breaking into her bedroom has been sectioned.
Obsessed Alex Gray had "delusions" that the Smile singer had plagiarised his lyrics to support her chart career.
The 31-year-old was handed indeterminate hospital and restraining orders for burglary and stalking at Harrow Crown Court, north London, on Friday, having previously attempted to contact the singer on social media and in person.
Ms Allen, known for songs including LDN and The Fear, was not present for the hour-long hearing, but a victim impact statement read before Judge Martyn Barklem said she was "left terrified for my and my children's safety", having been in the room when the defendant gained access to her north London flat in Queen's Park in October last year.
She said: "The impact of Mr Gray's actions upon me has been massive.
"I had already been incredibly disturbed and upset by the letters Mr Gray sent, and his contact on social media, but the break-in at my home was absolutely terrifying.
"I believe he came into my bedroom that night believing I would be alone.
"The fact that I was not alone was probably the reason why I don't think he went any further.
"I don't think this was a spur-of-the-moment decision, but rather something he thought about for some time."
Describing the moment she saw Gray emerge in her room, she said: "I didn't recognise the man shouting at me in my bedroom.
"I was in shock and could not sleep. The man's manner was eerie and so odd, I wondered if it could be the man who was sending me malicious letters. He came in thinking I was alone. He thought he knew me, but he didn't."
The court heard she opened her locked bedroom door, after she heard banging against it, where Gray was stood shouting: "Where is my father? What have you done with my father?"
The court heard Gray's father had died before the incident.
The singer, daughter of actor Keith Allen and sister to Game of Throne star Alfie, said she "lived in terror" that Gray "might break into my house again and attack me and my children".
She said: "I was too terrified to stay in my Queen's Park flat.
"I couldn't stay there knowing how easy it was for him to break in and how vulnerable my children were."
The court heard Gray stole a handbag, a mobile phone, jewellery, a hard drive, a set of keys, a glass vase and cash.
He already had an unspecified number of previous convictions, and had received a caution in 2008 after he arrived at her then home in London and handed her a CD containing love songs and a letter. He fled having grabbed post from the address, the court heard.
He was also reported for harassment again in 2010 having told Ms Allen he "created" - or was the creative force behind - one of her more famous songs, The Fear.
Giving evidence in court, consultant psychiatrist Dr Neil Hunt said Gray likely suffered from paranoid schizophrenia.
Sentencing, the judge said Gray's offending was "borne out of the long-standing, delusional, and utterly groundless" belief that Ms Allen had plagiarised lyrics written by him.
He said: "I make it clear that the (hospital) order I have made is not a punishment but is entirely for your well-being and that of the public."
In a statement outside court, Gray's solicitor Andy Cave said his client wished to apologise to "Miss Allen for the distress he has caused her".
The statement read: "It was never his intention to cause her any distress.
"He wishes to assure Miss Allen that he will not be pursuing her any further.
"He is aware he has significant work to do with his doctors and is looking forward to successfully achieving his release."