Importance Suicidal behavior is a significant clinical concern in individuals with borderline personality disorder (BPD), but the effectiveness of pharmacotherapy on reducing suicide risk has remained unknown. Objective To study the comparative effectiveness of different pharmacotherapies in preventing attempted or completed suicides in patients with BPD in Sweden. Design, Setting and Participants In this comparative effectiveness research study, nationwide Swedish register databases of inpatient care, specialized outpatient care, sickness absences, and disability pensions were used to identify patients aged 16 to 65 years with registered treatment contact due to BPD during 2006 to 2021. Data were analyzed from September to December 2022. A within-individual design was used, in which each patient was used as their own control to eliminate selection bias. To control protopathic bias, sensitivity analyses were conducted, in which the first 1 or 2 months of medication exposure were omitted from the analyses. Main outcomes and Measures Hazard ratio (HR) for attempted or completed suicide. Results A total of 22 601 patients with BPD (3540 [15.7%] men; mean [SD] age, 29.2 [9.9] years) were included. During the 16-year follow-up (mean [SD] follow-up, 6.9 [5.1] years), 8513 hospitalizations due to attempted suicide and 316 completed suicides were observed. Attention-deficit/hyperactive disorder (ADHD) medication treatment, compared with its nonuse, was associated with a decrease in the risk of attempted or completed suicide (HR, 0.83; 95% CI, 0.73-0.95; false discovery rate [FDR]–corrected P = .001). Treatment with mood stabilizers did not have a statistically significant association with the main outcome (HR, 0.97; 95% CI, 0.87-1.08; FDR-corrected P = .99). Antidepressant (HR, 1.38; 95% CI, 1.25-1.53; FDR-corrected P < .001) and antipsychotic (HR, 1.18; 95% CI, 1.07-1.30; FDR-corrected P < .001) treatments were associated with an elevated risk of attempted or completed suicide. Of the investigated pharmacotherapies, treatment with benzodiazepines was associated with the highest risk of attempted or completed suicide (HR, 1.61; 95% CI, 1.45-1.78; FDR-corrected P < .001). These results remained similar when controlling for potential protopathic bias. Conclusions and Relevance In this comparative effectiveness research study of a Swedish nationwide cohort, ADHD medication was the only pharmacological treatment associated with reduced risk of suicidal behavior among patients with BPD. Conversely, the findings suggest that benzodiazepines should be used with care among patients with BPD due to their association with increased risk of suicide.