Background Studies of occupation-associated suicide suggest physicians may be at a higher risk of suicide compared to nonphysicians. We set out to assess the risk of suicide and self-harm among physicians and compare it to nonphysicians. Methods We conducted a population-based, retrospective cohort study using registration data from the College of Physicians and Surgeons of Ontario from 1990 to 2016 with a follow-up to 2017, linked to Ontario health administrative databases. Using age- and sex-standardized rates and inverse probability-weighted, cause-specific hazards regression models, we compared rates of suicide, self-harm, and a composite of either event among all newly registered physicians to nonphysician controls. Results Among 35,989 physicians and 6,585,197 nonphysicians, unadjusted suicide events (0.07% vs. 0.11%) and rates (9.44 vs. 11.55 per 100,000 person-years) were similar. Weighted analyses found a hazard ratio of 1.05 (95% confidence interval: 0.69 to 1.60). Self-harm requiring health care was lower among physicians (0.22% vs. 0.46%; hazard ratio: 0.65, 95% confidence interval: 0.52 to 0.82), as was the composite of suicide or self-harm (hazard ratio: 0.70, 95% confidence interval: 0.57 to 0.86). The composite of suicide or self-harm was associated with a history of a mood or anxiety disorder (odds ratio: 2.84, 95% confidence interval: 1.17 to 6.87), an outpatient mental health visit in the past year (odds ratio: 3.08, 95% confidence interval: 1.34 to 7.10) and psychiatry visit in the preceding year (odds ratio: 3.87, 95% confidence interval: 1.67 to 8.95). Interpretation Physicians in Ontario are at a similar risk of suicide deaths and a lower risk of self-harm requiring health care relative to nonphysicians. Risk factors associated with suicide or self-harm may help inform prevention programs.