Objective Little is known about the prognosis of infections in patients with ankylosing spondylitis (AS) compared with patients without AS. The purpose of this study was to examine whether AS is associated with poorer outcomes in patients who are hospitalised with pneumonia. Methods In a population-based cohort study including patients with hospitalised pneumonia with and without AS, we compared 90-day rates of mortality, all-cause readmission (90 days post-discharge) and pulmonary complications including pulmonary embolism, empyema and pulmonary abscess. We used Cox regression analyses to compute crude and adjusted HRs while adjusting for sex, age and level of comorbidity. Results A total of 387 796 patients (median age 71 years) were hospitalised for pneumonia in Denmark between 1997 and 2017. Among these, 842 (0.2%) had AS (median age 65 years). The 90-day mortality was 12.5% in patients with AS and 15.5% in patients with non-AS pneumonia, with crude and adjusted 90-day HRs of 0.79 (95% CI 0.66 to 0.96) and 0.95 (95% CI 0.79 to 1.16), respectively. The 90-day post-discharge readmission rate was 27.3% in patients with AS and 25.4% in patients without AS, with a corresponding adjusted readmission HR of 1.12 (95% CI 0.98 to 1.27). Relative risk of pulmonary complications among patients with AS compared with patients without AS decreased over the study period, with adjusted HRs of 1.63 (95% CI 0.82 to 3.27) in 1997-2006 falling to 0.62 (95% CI 0.31 to 1.23) in 2007-2017. Conclusions AS is not associated with increased mortality following hospitalisation for pneumonia. Furthermore, no increased risk of readmission or pulmonary complications in patients with AS was detected in recent study years.