BackgroundAbnormal glycemic variability is common in the intensive care unit (ICU) and is associated with increased in-hospital mortality and major adverse cardiovascular events, but little is known about whether adverse outcomes are partly mediated by ventricular arrhythmias (VA). We aimed to explore the association between glycemic variability and VA in the ICU and whether VA related to glycemic variability mediate the increased risk of in-hospital death.MethodsWe extracted all measurements of blood glucose during the ICU stay from The Medical Information Mart for Intensive Care IV (MIMIC-IV) database version 2.0. Glycemic variability was expressed by the coefficient of variation (CV), which was calculated by the ratio of standard deviation (SD) and average blood glucose values. The outcomes included the incidence of VA and in-hospital death. The KHB (Karlson, KB & Holm, A) is a method to analyze the mediation effect for nonlinear models, which was used to decompose the total effect of glycemic variability on in-hospital death into a direct and VA-mediated indirect effect.ResultsFinally, 17,756 ICU patients with a median age of 64 years were enrolled; 47.2% of them were male, 64.0% were white, and 17.8% were admitted to the cardiac ICU. The total incidence of VA and in-hospital death were 10.6% and 12.8%, respectively. In the adjusted logistic model, each unit increase in log-transformed CV was associated with a 21% increased risk of VA (OR 1.21, 95% CI: 1.11–1.31) and a 30% increased risk (OR 1.30, 95% CI: 1.20–1.41) of in-hospital death. A total of 3.85% of the effect of glycemic variability on in-hospital death was related to the increased risk of VA.ConclusionHigh glycemic variability was an independent risk factor for in-hospital death in ICU patients, and the effect was caused in part by an increased risk of VA.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12933-023-01861-0.