Preoperative pneumonia in children with CHD may lead to longer stays in the ICU after surgery. However, research on the associated risk factors is limited. This study aims to evaluate the pre-, intra-, and postoperative risk factors contributing to extended ICU stays in these children. This retrospective cohort study collected data from 496 children with CHD complicated by preoperative pneumonia who underwent cardiac surgery following medical treatment at a single centre from 2017 to 2022. We compared the clinical outcomes of patients with varying ICU stays and utilised multivariate logistic regression analysis and multiple linear regression analyses to evaluate the risk factors for prolonged ICU stays. The median ICU stay for the 496 children was 7 days. Bacterial infection, severe pneumonia, and Risk Adjustment for Congenital Heart Surgery-1 were independent risk factors for prolonged ICU stays following cardiac surgery (P < 0.05). CHD complicated by pneumonia presents a significant treatment challenge. Better identification of the risk factors associated with long-term postoperative ICU stays in these children, along with timely diagnosis and treatment of respiratory infections in high-risk populations, can effectively reduce ICU stays and improve resource utilisation.