This study assessed the clinical efficacy of nirmatrelvir plus ritonavir (NMV‐r) in treating patients with coronavirus disease‐2019 (COVID‐19) and substance use disorders (SUDs). This study included two cohorts: the first examined patients with SUDs, with and without a prescription for NMV‐r, while the second compared patients prescribed with NMV‐r, with and without a diagnosis of SUDs. SUDs were defined using ICD‐10 codes, related to SUDs, including alcohol, cannabis, cocaine, opioid, and tobacco use disorders (TUD). Patients with underlying SUDs and COVID‐19 were identified using the TriNetX network. We used 1:1 propensity score matching to create balanced groups. The primary outcome of interest was the composite outcome of all‐cause hospitalization or death within 30 days. Propensity score matching yielded two matched groups of 10 601 patients each. The results showed that the use of NMV‐r was associated with a lower risk of hospitalization or death, 30 days after COVID‐19 diagnosis (hazard ratio (HR), 0.640; 95% confidence interval (CI): 0.543–0.754), as well as a lower risk of all‐cause hospitalization (HR, 0.699; 95% CI: 0.592–0.826) and all‐cause death (HR, 0.084; 95% CI: 0.026–0.273). However, patients with SUDs had a higher risk of hospitalized or death within 30 days of COVID‐19 diagnosis than those without SUDs, even with the use of NMV‐r (HR, 1.783; 95% CI: 1.399–2.271). The study also found that patients with SUDs had a higher prevalence of comorbidities and adverse socioeconomic determinants of health than those without SUDs. Subgroup analysis showed that the benefits of NMV‐r were consistent across most subgroups with different characteristics, including age (patients aged ≥60 years [HR, 0.507; 95% CI: 0.402–0.640]), sex (women [HR, 0.636; 95% CI: 0.517–0.783] and men [HR, 0.480; 95% CI: 0.373–0.618]), vaccine status (vaccinated <2 doses [HR, 0.514; 95% CI: 0.435–0.608]), SUD subtypes (alcohol use disorder [HR, 0.711; 95% CI: 0.511– 0.988], TUD [HR, 0.666; 95% CI: 0.555–0.800]) and Omicron wave (HR, 0.624; 95% CI: 0.536–0.726). Our findings indicate that NMV‐r could reduce all‐cause hospitalization and death in the treatment of COVID‐19 among patients with SUDs and support the use of NMV‐r for treating patients with SUDs and COVID‐19.