Background: Guidelines recommend macrolides and fluoroquinolones in patients hospitalized with community-acquired pneumonia (CAP), but their use has been associated with cardiac events. Objective: To quantify associations between macrolide and fluoroquinolone use and cardiac events in patients hospitalized with CAP in non-ICU wards. Design: Post-hoc analysis of a cluster-randomized trial Setting: Six hospitals in the Netherlands Patients: CAP patients admitted to non-ICU wards and without a cardiac event on admission Measurements: Cause-specific hazard ratios were calculated for effects of time-dependent macrolide and fluoroquinolone exposure on cardiac events, defined as occurrence of new or worsening heart failure, arrhythmia, or myocardial ischemia during hospitalization. Results: Cardiac events occurred in 146 (6.9%) of 2,107 patients and included episodes of heart failure (n=101, 4.8%), arrhythmia (n=53, 2.5%), and myocardial ischemia (n=14, 0.7%). Cardiac events occurred in 11 of 207 (5.3%), 18 of 250 (7.2%), and 31 of 277 (11.2%) patients exposed to azithromycin, clarithromycin, and erythromycin for at least one day, respectively, and in 9 of 234 (3.8%), 5 of 194 (2.6%), and 23 of 566 (4.1%) patients exposed to ciprofloxacin, levofloxacin, and moxifloxacin, respectively. Hazard ratios for any cardiac event, adjusted for confounding, were 0.89 (95% confidence interval (CI) 0.48 to 1.67), 1.06 (95% CI 0.61 to 1.83) and 1.68 (95% CI 1.07 to 2.62) for azithromycin, clarithromycin, and erythromycin, respectively, and adjusted hazard ratios were 0.86 (95% CI 0.47 to 1.57), 0.42 (95% CI 0.18 to 0.96) and 0.62 (95% CI 0.39 to 0.99) for ciprofloxacin, levofloxacin, and moxifloxacin, respectively. Erythromycin was associated with an adjusted hazard ratio of 2.08 (95% CI 1.25 to 3.46) for heart failure. Limitations: Possibility of confounding by indication and observational bias Conclusions: Among patients with CAP hospitalized to non-ICU wards, erythromycin use was associated with a 68% increased risk of hospital-acquired cardiac events, mainly heart failure. Levofloxacin and moxifloxacin were associated with a lower risk of heart failure. Registration: The original trial was registered under ClinicalTrials.gov Identifier NCT01660204 Funding Source: The Netherlands Organization for Health Research and Development (ZONmw, Health care efficiency research, project id: 171202002).