Background: Sleep difficulties might be a contributory causal factor in the occurrence of mental health problems. If this is true, improving sleep should benefit psychological health. We aimed to determine whether treating insomnia leads to a reduction in paranoia and hallucinations. Methods: We did this single-blind, randomised controlled trial (OASIS) at 26 UK universities. University students with insomnia were randomly assigned (1:1) with simple randomisation to receive digital cognitive behavioural therapy (CBT) for insomnia or usual care, and the research team were masked to the treatment. Online assessments took place at weeks 0, 3, 10 (end of therapy), and 22. The primary outcome measures were for insomnia, paranoia, and hallucinatory experiences. We did intention-to-treat analyses. The trial is registered with the ISRCTN registry, number ISRCTN61272251. Findings: Between March 5, 2015, and Feb 17, 2016, we randomly assigned 3755 participants to receive digital CBT for insomnia (n=1891) or usual practice (n=1864). Compared with usual practice, the sleep intervention at 10 weeks reduced insomnia (adjusted difference 4·78, 95% CI 4·29 to 5·26, Cohen's d=1·11; p<0·0001), paranoia (−2·22, −2·98 to −1·45, Cohen's d=0·19; p<0·0001), and hallucinations (−1·58, −1·98 to −1·18, Cohen's d=0·24; p<0·0001). Insomnia was a mediator of change in paranoia and hallucinations. No adverse events were reported. Interpretation: To our knowledge, this is the largest randomised controlled trial of a psychological intervention for a mental health problem. It provides strong evidence that insomnia is a causal factor in the occurrence of psychotic experiences and other mental health problems. Whether the results generalise beyond a student population requires testing. The treatment of disrupted sleep might require a higher priority in mental health provision. Funding: Wellcome Trust.