IntroductionPatients with community-acquired pneumonia (CAP) admitted to the intensive care unit (ICU) have high mortality rates during the acute infection and up to ten years thereafter. Recommendations from international CAP guidelines include macrolide-based treatment. However, there is no data on the long-term outcomes of this recommendation. Therefore, we aimed to determine the impact of macrolide-based therapy on long-term mortality in this population.MethodsRegistered patients in the MIMIC-IV database 16 years or older and admitted to the ICU due to CAP were included. Multivariate analysis, targeted maximum likelihood estimation (TMLE) to simulate a randomised controlled trial, and survival analyses were conducted to test the effect of macrolide-based treatment on mortality six-month (6 m) and twelve-month (12 m) after hospital admission. A sensitivity analysis was performed excluding patients withPseudomonas aeruginosaor MRSA pneumonia to control for Healthcare-Associated Pneumonia (HCAP).Results3775 patients were included, and 1154 were treated with a macrolide-based treatment. The non-macrolide-based group had worse long-term clinical outcomes, represented by 6 m [31.5 (363/1154) vs 39.5 (1035/2621),p< 0.001] and 12 m mortality [39.0 (450/1154) vs 45.7 (1198/2621),p< 0.001]. The main risk factors associated with long-term mortality were Charlson comorbidity index, SAPS II, septic shock, and respiratory failure. Macrolide-based treatment reduced the risk of dying at 6 m [HR (95% CI) 0.69 (0.60, 0.78),p< 0.001] and 12 m [0.72 (0.64, 0.81),p< 0.001]. After TMLE, the protective effect continued with an additive effect estimate of − 0.069.ConclusionMacrolide-based treatment reduced the hazard risk of long-term mortality by almost one-third. This effect remains after simulating an RCT with TMLE and the sensitivity analysis for the HCAP classification.Supplementary InformationThe online version contains supplementary material available at 10.1186/s13054-023-04466-x.