Background: Postoperative infection is a common complication in hip fracture patients and the risk appears to have increased during the last decade. However, the impact of infection on mortality after hip fracture surgery remains unclear. Purpose: We aimed to examine the association between infection (any, as well as specific infections), with all-cause mortality following hip fracture surgery. Methods: Using Danish nationwide registries, we conducted a population-based cohort study on 74,771 hip fracture patients ≥ 65 years old operated from 2005-2016. We included hospital-treated infection as a time-varying exposure, and calculated 30-days mortality rate per 1000 person-years (PY). We used time-varying Cox Proportional Hazard Regression to compute 30-days adjusted hazards ratios (aHRs) with 95 % confidence interval (CI) comparing the mortality of hip fracture patients with and without infections. We adjusted for sex, age, comorbidities, medication use, and marital status. Results: Within 30 days of surgery, 9,592 (12.8%) patients developed a hospital-treated infection. Among these, 30-days mortality was 8.43 per 1000 PY compared with 3.34 among patients without infection (aHR=2.72, 95 % CI: 2.56-2.88). For patients who developed pneumonia, aHR was 4.18 (95 % CI: 3.91-4.48), whereas the aHR was 8.86 (95 % CI: 7.88-9.95) for patients who developed systemic sepsis. For patients who sustained reoperation due to infection, aHR was 2.95 (95 %CI: 1.88-4.64). The mortality was higher in infected vs. noninfected patients irrespective of patients' age, sex and comorbidity. Conclusion: Infection within 30 days of hip fracture surgery is associated with substantially increased mortality risk. Further research should improve our knowledge about patients at increased risk and prevention measures for specific infections.