JK Rowling has revealed that she thought of killing herself while suffering from depression as a struggling single mother.

The Harry Potter author says she was prescribed cognitive behavioral therapy after suffering “suicidal thoughts” in the aftermath of separation from her first husband, Jorge Arantes, a Portuguese journalist.

She is now one of the world’s richest women, but at the time lived in a cramped flat in Edinburgh with her baby daughter Jessica. Rowling was only able to afford the rent after a friend paid the deposit. It was there she began writing the first Harry Potter book.

While Rowling, 42, has spoken before of her battle with depression, it is the first time she has admitted that she contemplated suicide. She said she finally sought professional help.

“Mid-twenties life circumstances were poor and I really plummeted,” said Rowling. “The thing that made me go for help . . . was probably my daughter. She was something that earthed me, grounded me, and I thought, this isn’t right, this can’t be right, she cannot grow up with me in this state.”

Rowling said her usual GP was away, and the replacement doctor sent her away. “She said, ‘If you ever feel a bit low, come and speak to the practice nurse’ and dismissed me.”

Rowling added: “We’re talking suicidal thoughts here, we’re not talking ‘I’m a little bit miserable’.

Two weeks later I had a phone call from my regular GP who had looked back over the notes . . . She called me back in and I got counseling through her.

“She absolutely saved me because I don’t think I would have had the guts to go and do it twice.”

Cognitive behavioral therapy typically involves a series of sessions with a counselor and is designed to help patients control negative thoughts. The technique is recommended by the health department for depressive disorders, anxiety, bulimia and posttraumatic stress disorder.

Rowling, whose Harry Potter novels have sold more than 400m copies worldwide and spawned a billion dollar industry, said she was happy to discuss her mental health problems to challenge the stigma associated with depressive illness.

“I have never been remotely ashamed of having been depressed. Never,” she said in an interview with Adeel Amini, 22, for a student magazine at Edinburgh University.

“What’s to be ashamed of? I went through a really rough time and I am quite proud that I got out of that.”

Mental health campaigners welcomed Rowling’s decision to speak publicly about her struggle with suicidal depression.

Celia Richardson, campaigns director of the Mental Health Foundation, said: “JK Rowling is a wonderful role model and it’s brilliant she has chosen to talk about this.”