Background: Loneliness has been linked to greater substance use, especially among women. Yet little is known about how loneliness is associated with treatment outcomes for patients with opioid use disorder (OUD). Objectives: We evaluated how patient reports of using illicit opioids (i.e., heroin or nonprescription pain medications) are linked to perceptions of loneliness in a sample of adults receiving methadone maintenance treatment (MMT), and whether this link varies by gender. Methods: Participants for this cross-sectional observational study included 371 MMT patients aged 18 and older drawn from four opioid treatment programs in Southern New England and the Pacific Northwest. Patients completed a self-administered survey assessing sociodemographic and health information, loneliness, illicit opioid use, and MMT characteristics. Logistic regressions were estimated to examine the link between patient odds of illicit opioid use in the past month and perceived loneliness. Results: Patient gender moderated the association between illicit opioid use and loneliness such that severe loneliness was associated with higher odds of using illicit opioids among women (OR = 3.00, 95% CI [1.19, 7.57], p = .020) but lower odds of using illicit opioids among men (OR = 0.35, 95% CI [0.14, 0.87], p = .024), accounting for age, marital status, work status, depressive symptoms, and MMT characteristics (treatment episode, treatment duration, and methadone dose).