Opioid analgesics may be initiated following surgical and medical hospitalization or in ambulatory settings; rates of subsequent long-term opioid (LTO) use have not been directly compared. This retrospective cohort study of the Veterans Health Administration (VHA) included all patients receiving a new outpatient opioid prescription from a VHA provider in fiscal year 2011. If a new outpatient prescription was filled within 2 days following hospital discharge, the initiation was considered a discharge prescription. LTO use was defined as an episode of continuous opioid supply lasting a minimum of 90 days and beginning within 30 days of the initial prescription. We performed bivariate and multivariate analyses to identify the factors associated with LTO use following surgical and medical discharges. Following incident prescription, 5.3% of discharged surgical patients, 15.2% of discharged medical patients, and 19.3% of outpatient opioid initiators received opioids long term. Medical and surgical patients differed; surgical patients were more likely to receive shorter prescription durations. Predictors of LTO use were similar in medical and surgical patients; the most robust predictor in both groups was the number of days’ supply of the initial prescription (odds ratio [OR] = 1.24 and 95% confidence interval [CI], 1.12–1.37 for 8–14 days; OR = 1.56 and 95% CI, 1.39–1.76 for 15–29 days; and OR = 2.59 and 95% CI, 2.35–2.86 for >30 days) compared with the reference group receiving ≤7days. Rates of subsequent LTO use are higher among discharged medical patients than among surgical patients. Characteristics of opioid prescribing within the initial 30 days, including initial dose and days prescribed, were strongly associated with LTO use.