Nightmares are vivid, extended and extremely dysphoric dreams that awaken the dreamer. Twin studies indicate that nightmare frequency has a heritability between 36 and 51% providing evidence for genetic factors underlying predisposition to nightmares. Furthermore, while crosssectional epidemiological findings suggest that heavy alcohol usage, traumatic experiences and psychiatric diseases associate with nightmares, the causal relationships between these conditions and nightmares have remained unknown. To examine the biological mechanisms behind nightmares, we performed a genome-wide association study in 28,596 individuals from Finland and the United States. We identified individual genetic variants that predispose to nightmares near MYOF (rs701873, p=2.18e-8) and PTPRJ (rs11039471,p=3.7e-8), a gene previously associated with sleep duration. We found a strong genetic correlation between the frequency of nightmares and traits related to personality and psychiatric disorders; neuroticism (rg=0.59, p=8e-7), post-traumatic stress disorder (PTSD) (rg=0.58, p=0.004) as well as major depressive disorder (rg=0.68, p=7e-4), and sleep traits; and daytime sleepiness (rg=0.62, p=1e-6) and insomnia (rg=0.50, p=1.87e-5). Analysis of directionality using mendelian randomization showed a significant effect from feelings of fed-up (p=0.001), nervous (p=0.004) and miserableness (p=0.0045) to nightmares with no evidence of pleiotropy and no evidence of nightmares predisposing to psychiatric or psychological problems. Our findings suggest that nightmares are caused by unique genetic risk factors, and here we identify the first individual genetic associations. In addition, a substantial effect on nightmares is conveyed through underlying psychological and sleep problems, with psychological problems being causal for nightmares.