Background Engaging, interactive, and automated virtual reality (VR) treatments might help solve the unmet needs of individuals with mental health disorders. We tested the efficacy of an automated cognitive intervention for fear of heights guided by an avatar virtual coach (animated using motion and voice capture of an actor) in VR and delivered with the latest consumer equipment. Methods We did a randomised trial of automated VR versus usual care. We recruited adults aged older than 18 years with a fear of heights by radio advertisements in Oxfordshire, UK. We diagnosed fear of heights if participants scored more than 29 on the Heights Interpretation Questionnaire (HIQ). We randomly allocated participants by computer in a 1:1 ratio to either automated VR delivered in roughly six 30-min sessions administered about two to three times a week over a 2-week period (intervention group) or to usual care (control group). Randomisation was stratified by severity of fear of heights. The research team, who were unaware of the random allocation, administered three fear-of-height assessments, at baseline (0 weeks), at the end of treatment (2 weeks), and at follow-up (4 weeks). The primary outcome measure was HIQ score (range 16–80, with higher scores indicating greater severity). This trial is registered with the ISRCTN registry, number ISRCTN11898283. Findings Between Nov 25, 2017, and Feb 27, 2018, 100 individuals were enrolled and underwent randomisation, of whom 49 were assigned to the VR treatment group and 51 to the control group. All participants completed the 4-week follow-up. The mean total treatment time in VR was 124·43 min (SD 34·23). Compared with participants in the control group, the VR treatment reduced fear of heights at the end of treatment (mean change score −24·5 [SD 13·1] in the VR group vs −1·2 [7·3] in the control group; adjusted difference −24·0, 95% CI −27·7 to −20·3; Cohen's d=2·0; p<0·0001). The benefit was maintained at follow-up (mean change score −25·1 [SD 13·9] in the VR group vs −1·5 [7·8] in the control group; adjusted difference −24·3, 95% CI −27·9 to −20·6; Cohen's d=2·0; p<0·0001). The number needed to treat to at least halve the fear of heights was 1·3. No adverse events were reported. Interpretation Psychological therapy delivered automatically by a VR coach can produce large clinical benefits. Evidence-based VR treatments have the potential to greatly increase treatment provision for mental health disorders.