Diversity in the medical workforce is critical to improve health care access and achieve equity for resource-limited communities. Despite increased efforts to recruit diverse medical trainees, there remains a large chasm between the racial and ethnic and socioeconomic composition of the patient population and that of the physician workforce. To analyze student attrition from medical school by sociodemographic identities. This retrospective cohort study included allopathic doctor of medicine (MD)-only US medical school matriculants in academic years 2014-2015 and 2015-2016. The analysis was performed from July to September 2021. The main outcome was attrition, defined as withdrawal or dismissal from medical school for any reason. Attrition rate was explored across 3 self-reported marginalized identities: underrepresented in medicine (URiM) race and ethnicity, low income, and underresourced neighborhood status. Logistic regression was assessed for each marginalized identity and intersections across the 3 identities. Among 33 389 allopathic MD-only medical school matriculants (51.8% male), 938 (2.8%) experienced attrition from medical school within 5 years. Compared with non-Hispanic White students (423 of 18 213 [2.3%]), those without low income (593 of 25 205 [2.3%]), and those who did not grow up in an underresourced neighborhood (661 of 27 487 [2.4%]), students who were URiM (Hispanic [110 of 2096 (5.2%); adjusted odds ratio (aOR), 1.41; 95% CI, 1.13-1.77], non-Hispanic American Indian/Alaska Native/Native Hawaiian/Pacific Islander [13 of 118 (11.0%); aOR, 3.20; 95% CI, 1.76-5.80], and non-Hispanic Black/African American [120 of 2104 (5.7%); aOR, 1.41; 95% CI, 1.13-1.77]), those who had low income (345 of 8184 [4.2%]; aOR, 1.33; 95% CI, 1.15-1.54), and those from an underresourced neighborhood (277 of 5902 [4.6%]; aOR, 1.35; 95% CI, 1.16-1.58) were more likely to experience attrition from medical school. The rate of attrition from medical school was greatest among students with all 3 marginalized identities (ie, URiM, low income, and from an underresourced neighborhood), with an attrition rate 3.7 times higher than that among students who were not URiM, did not have low income, and were not from an underresourced neighborhood (7.3% [79 of 1086] vs 1.9% [397 of 20 353]; P < .001). This retrospective cohort study demonstrated a significant association of medical student attrition with individual (race and ethnicity and family income) and structural (growing up in an underresourced neighborhood) measures of marginalization. The findings highlight a need to retain students from marginalized groups in medical school.