BackgroundSedentary behavior is prevalent among people with diabetes and is associated with unfavorable cardiometabolic health. However, there is limited evidence regarding the impact of replacing sedentary time (ST) with physical activity on mortality in people with prediabetes and diabetes. We prospectively examined the association between accelerometer-measured ST and mortality among people with prediabetes and diabetes after adjusting for demographic characteristics, lifestyle factors, and moderate- to vigorous-intensity PA (MVPA). We further determined the effect of replacing ST with equal time of different types of physical activities on all-cause mortality.MethodsWe included 1242 adults with prediabetes and 1037 with diabetes from the National Health and Nutrition Examination Survey. Restricted cubic splines were fitted to determine the dose–response association between ST and overall mortality. Isotemporal substitution modeling was used to explore the hazard ratio (HR) effects of ST replacement.ResultsDuring a median follow-up of 14.1 years, 424 adults with prediabetes and 493 with diabetes died. Compared with the lowest tertile of ST, the multivariable-adjusted HRs for all-cause mortality in the highest tertile were 1.76 (95% confidence interval [CI] 1.19, 2.60) for participants with prediabetes and 1.76 (1.17, 2.65) for those with diabetes. Additionally, a linear association between ST and all-cause mortality was observed in adults with prediabetes and diabetes, with HRs for each 60 min/day increment in ST of 1.19 (1.10, 1.30) and 1.25 (1.12, 1.40), respectively. Isotemporal substitution results indicated that individuals with prediabetes whose ST was replaced by 30 min of light-intensity physical activity (LPA) and MVPA had 9% and 40% lower all-cause mortality, respectively. In people with diabetes, replacing sedentary behavior with an equivalent time of LPA and MVPA was also associated with mortality risk reduction (HR 0.89; 95% CI 0.84, 0.95 for LPA; HR 0.73; 95% CI 0.49, 1.11 for MVPA).ConclusionsHigher ST was associated in a dose–response manner with an increased risk of premature mortality among adults with prediabetes and diabetes. Statistically replacing ST with LPA was potentially beneficial for health in this high-risk population.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12966-023-01488-0.