BackgroundThe objective of this investigation was to explore the correlation between the visceral adiposity index (VAI) and depression, and to analyze how type 2 diabetes mellitus (T2DM) may influence this relationship. MethodsThis study included data of 12,378 participants sourced from the National Health and Nutrition Examination Survey (NHANES) 2005–2018. Utilizing multivariate logistic regression and restricted cubic spline (RCS) regression, we examined the correlation between VAI and depression. Additionally, we investigated the interactive and mediating effects of T2DM on the association between VAI and depression. ResultsControlling for all potential confounders, the Ln logarithmic transformation of VAI showed a significant positive correlation with depression [odds ratio (OR) = 1.16, 95 % confidence interval (CI): 1.01–1.35, P = 0.041]. T2DM exhibited a notable interaction effect on the relationship connecting lnVAI and depression (P for interaction = 0.013). Specifically, the T2DM group exhibited a notable positive correlation between lnVAI and depression (OR = 1.46, 95 % CI: 1.17–1.82, P < 0.001), whereas such correlation didn't reach statistical significance within the non-T2DM group. The RCS model revealed a J-shaped nonlinear link between lnVAI and depression, with an inflection point value of 0.052. Mediation analysis indicated that diabetes accounted for 8.0 % of the correlation between lnVAI and depression. Furthermore, sensitivity analysis confirmed the consistency of these findings. ConclusionsA J-shaped nonlinear dose-response relationship was observed between lnVAI and depression among American adults, with a threshold of 0.052. T2DM not only served as a mediator between the two variables but also modified their association.