Background Autism spectrum disorder (ASD) and obsessive-compulsive disorder (OCD) are often comorbid and share similarities across some cognitive phenotypes, including certain aspects of attention. However, no functional magnetic resonance imaging studies have compared the underlying neural mechanisms contributing to these shared phenotypes. Methods Age- and IQ-matched boys (11–17 years old) with ASD (n = 20), boys with OCD (n = 20), and healthy control boys (n = 20) performed a parametrically modulated psychomotor vigilance functional magnetic resonance imaging task. Brain activation and performance were compared among adolescents with OCD, adolescents with ASD, and control adolescents. Results Whereas boys with ASD and OCD were not impaired on task performance, there was a significant group by attention load interaction in several brain regions. With increasing attention load, left inferior frontal cortex/insula and left inferior parietal lobe/pre/post-central gyrus were progressively less activated in boys with OCD relative to the other two groups. In addition, boys with OCD showed progressively increased activation with increasing attention load in rostromedial prefrontal/anterior cingulate cortex relative to boys with ASD and control boys. Shared neurofunctional abnormalities between boys with ASD and boys with OCD included increased activation with increasing attention load in cerebellum and occipital regions, possibly reflecting increased default mode network activation. Conclusions This first functional magnetic resonance imaging study to compare boys with ASD and OCD showed shared abnormalities in posterior cerebellar–occipital brain regions. However, boys with OCD showed a disorder-specific pattern of reduced activation in left inferior frontal and temporo-parietal regions but increased activation of medial frontal regions, which may potentially be related to neurobiological mechanisms underlying cognitive and clinical phenotypes of OCD.