The researchers also discovered an association between watching YouTube content and obsessive-compulsive disorder, with every hour watching streaming videos linked to an 11 percent increased risk.
Also, spending too much screen time in childhood has been linked to eating disorders, mental health problems and gambling addiction later in life.
The researchers blamed YouTube algorithms and addictive video game content for promoting compulsive feelings in pre-adolescence.
In this study, scientists at the University of California, San Francisco, conducted the tests on 9,204 children between the ages of 9 and 10.
At the start of the study, which was published in the Journal of Adolescent Health, participants were asked how much time they had spent playing games and watching TV.
Two years later, their parents were called and asked if their children had been diagnosed with obsessive-compulsive disorder or had symptoms of the condition.
The researchers found that youngsters spend an average of 3 hours and 54 minutes in front of screens each day. This time does not include time in front of devices in schools for educational purposes.
During the follow-up, the scientists discovered that 405 children, or 4.4 percent, had been diagnosed with obsessive-compulsive disorder.
The results indicated that children who spent more time playing video games or streaming videos were more likely to be infected.
Remarkably, texting, video chatting, and time spent on social media weren't associated with a higher risk, but the scientists warned that this may be because young people in this age group don't use it as much. The researchers said the results may be different with older teens.