The Dietary Inflammatory Index (DII) is a composite nutritional index that has gained significant attention in the past decade due to its association with physical and mental well-being. To accurately assess the precise effects of DII on health outcomes, the effects of nutrients and foods need to be adjusted. This study aimed to investigate the association between DII and mental disorders (depression, anxiety, and stress) using multilevel modeling to minimize the bias of the previous methods. This cross-sectional analytical study was conducted using data from the initial phase of the Tehran University of Medical Sciences Employees' Cohort Study (TEC). Nutritional information was obtained through a dish-based semi-quantitative food frequency questionnaire (DFQ), while psychological data were collected using the depression, anxiety and stress scale (DASS-42). The acquired data were analyzed using multilevel modeling in three levels (foods, nutrients, and DII, respectively) through GLIMMIX in the SAS software. A total of 3,501 individuals participated in this study. The results of the multilevel model demonstrated a significant statistical association between DII and mental disorders after adjusting for baseline characteristics, nutrients and foods. For each unit increase in DII, the mean scores for stress, anxiety, and depression increased by 3.55, 4.26, and 3.02, respectively (p < 0.001). Based on the multilevel model's findings, it is recommended to minimize the use of pro-inflammatory nutrients and foods to increase the mental health. Multilevel data analysis has also been recommended in nutritional studies involving nested data to obtain more accurate and plausible estimates.