Purpose: To explore the association between the number of medications and mortality in geriatric inpatients taking activities of daily living and comorbidities into account. Methods: A nationwide population-based cohort study was performed including all patients aged ≥ 65 years admitted to geriatric departments in Denmark during 2005–2014. The outcome of interest was mortality. Activities of daily living using Barthel Index (BI) were measured at admission. National health registers were used to link data on an individual level extracting data on medications, and hospital diseases. Patients were followed to the end of study (31/12/2015), death, or emigration, which ever occurred first. Kaplan–Meier survival curves were used to estimate crude survival proportions. Univariable and multivariable analyses were performed using Cox regression. The multivariable analysis were adjusted for age, marital status, period of hospital admission, BMI, and BI (model 1), and additionally either number of diseases (model 2) or Charlson comorbidity index (model 3). Results: We included 74,603 patients (62.8% women), with a median age of 83 (interquartile range [IQR] 77–88) years. Patients used a median of 6 (IQR 4–9) medications. Increasing number of medications was associated with increased overall, 30-day, and 1-year mortality in all three multivariable models for both men and women. For each extra medication, the mortality increased by 3% in women and 4% in men in the fully adjusted model. Conclusion: Increasing number of medications was associated with mortality in this nationwide cohort of geriatric inpatients. Our findings highlight the importance of polypharmacy in older patients with comorbidities.