Attention-deficit hyperactivity disorder (ADHD) and autism spectrum disorder (ASD) are highly heritable neurodevelopmental conditions, with considerable overlap in their genetic etiology. We dissected their shared and distinct genetic etiology by cross-disorder analyses of large datasets. We identified seven loci shared by the disorders and five loci differentiating them. All five differentiating loci showed opposite allelic directions in the two disorders and significant associations with other traits, including educational attainment, neuroticism and regional brain volume. Integration with brain transcriptome data enabled us to identify and prioritize several significantly associated genes. The shared genomic fraction contributing to both disorders was strongly correlated with other psychiatric phenotypes, whereas the differentiating portion was correlated most strongly with cognitive traits. Additional analyses revealed that individuals diagnosed with both ASD and ADHD were double-loaded with genetic predispositions for both disorders and showed distinctive patterns of genetic association with other traits compared with the ASD-only and ADHD-only subgroups. These results provide insights into the biological foundation of the development of one or both conditions and of the factors driving psychopathology discriminatively toward either ADHD or ASD.