This study aimed to estimate the strength of association between prescriptions of glucose-dependent insulinotropic polypeptide (GIP) and/or glucagon-like peptide-1 receptor agonists (GLP-1 RA) and the incidence of opioid overdose and alcohol intoxication in patients with opioid use disorder (OUD) and alcohol use disorder (AUD), respectively. This study also aimed to compare the strength of the GIP/GLP-1 RA and substance use-outcome association among patients with comorbid type 2 diabetes and obesity. A retrospective cohort study analyzing de-identified electronic health record data from the Oracle Cerner Real-World Data. About 136 United States of America health systems, covering over 100 million patients, spanning January 2014 to September 2022. The study included 503 747 patients with a history of OUD and 817 309 patients with a history of AUD, aged 18 years or older. The exposure indicated the presence (one or more) or absence of GIP/GLP-1 RA prescriptions. The outcomes were the incidence rates of opioid overdose in the OUD cohort and alcohol intoxication in the AUD cohort. Potential confounders included comorbidities and demographic factors. Patients with GIP/GLP-1 RA prescriptions demonstrated statistically significantly lower rates of opioid overdose [adjusted incidence rate ratio (aIRR) in OUD patients: 0.60; 95% confidence interval (CI) = 0.43-0.83] and alcohol intoxication (aIRR in AUD patients: 0.50; 95% CI = 0.40-0.63) compared to those without such prescriptions. When stratified by comorbid conditions, the rate of incident opioid overdose and alcohol intoxication remained similarly protective for those prescribed GIP/GLP-1 RA among patients with OUD and AUD. Prescriptions of glucose-dependent insulinotropic polypeptide and/or glucagon-like peptide-1 receptor agonists appear to be associated with lower rates of opioid overdose and alcohol intoxication in patients with opioid use disorder and alcohol use disorder. The protective effects are consistent across various subgroups, including patients with comorbid type 2 diabetes and obesity.