This study examines medical conditions diagnosed prior to the diagnosis of autism spectrum disorder (ASD). Using a matched case control design with 3911 ASD cases and 38,609 controls, we found that 38 out of 79 medical conditions were associated with increased ASD risk. Developmental delay, mental health, and neurology conditions had the strongest associations (ORs 2.0-23.3). Moderately strong associations were observed for nutrition, genetic, ear nose and throat, and sleep conditions (ORs 2.1-3.2). Using machine learning methods, we clustered children based on their medical conditions prior to ASD diagnosis and demonstrated ASD risk stratification. Our findings provide new evidence indicating that children with ASD have a disproportionate burden of certain medical conditions preceding ASD diagnosis.