Early warning signs of self-harm can appear in children almost a decade before it starts, say researchers.
The team at the University of Cambridge found two distinct groups that were more likely to harm themselves.
The first included those who struggle to control their emotions, and the second featured youngsters more willing to take risks than others their age.
The findings may mean there is a large window of opportunity to improve children's mental health.
About one-in-six in the study reported self-harming by the age of 14. Self-harm is in turn linked to a higher risk of suicide.
"Our current way of supporting them is overwhelmed, we typically wait for problems to escalate and then intervene to see if we can do anything," Dr Duncan Astle, one of the researchers, told the BBC.
"We really need to shift to a preventative, proactive model."
The team used a type of artificial intelligence to analyse data from 11,000 children, who were born in the UK around the turn of the millennium.
The AI looked for patterns in the data to understand which children were more likely to self-harm, and what increased their risk.
The results have been published in the Journal of the American Academy of Child and Adolescent Psychiatry.
The first group had a long history of mental health disorders. Difficulty controlling their emotions, being bullied, and parents with mental health problems all increased the risk.
Even having emotional regulation difficulties at the age of five led to a 30-50% higher risk as a teenager.
"The second, much larger group was much more surprising, as they don't show the usual traits that are associated with those who self-harm," said researcher Stepheni Uh.
Their higher risk was linked to risk-taking behaviours, and lacking a supportive group of friends.
Poor sleep and low-self esteem increased the risk of self-harm in both groups.
However, the researchers say the findings show there is an opportunity to intervene and reduce the chances of children self-harming.
They suggest programmes to boost children's self-esteem, anti-bullying measures in schools, and advice on improving quality of sleep could reduce self-harm later in life.
This study is also part of a larger project to understand the origins of mental health disorders, and find new ways of preventing them.
Miss Uh added: "This approach has the potential to explore how adversity may impact brain and child development in different groups of children.
"It could also help us understand the consequences of adversity, such as other mental health problems they may face as adolescents."
Tom Madders, from the charity YoungMinds, said: "We welcome any new research in this area, especially if it results in more early support for young people.
"While there is higher awareness about mental health than in the past, many young people who self-harm still find it hard to reach out for help until they hit crisis point.
"For those who do seek help, it can still be really difficult to get early support."
Follow James on Twitter