OBJECTIVE: To evaluate the association between major depressive episodes and diet quality among Brazilian adults and older adults. METHODS: We conducted a cross-sectional, population-based study using data from the two editions of the Brazilian National Health Survey (PNS in the Portuguese acronym) conducted in 2013 and 2019. Major depressive episodes were assessed using the Patient Health Questionnaire-9 (PHQ-9) and classified in two ways: based on a cutoff point of ≥ 9 points on the scale and according to the diagnostic criteria of the Statistical Manual of Mental Disorders. Diet quality was assessed using a diet quality score that considered the week consumption of seven food items. We used linear regression models to explore the association between major depressive episodes and diet quality score. Sensitivity analysis evaluating the association between major depressive episodes and each food item that composed the diet quality score was performed. RESULTS: In both 2013 and 2019, individuals with major depressive episodes had a diet quality score 0.20 standard deviations higher compared to their peers, indicating a worse diet quality, regardless of the criteria used to define exposure and the potential confounders. Sensitivity analysis revealed a lower prevalence of regular consumption of beans, vegetables, fruits, and milk, and a higher prevalence of regular consumption of sugar-sweetened beverages and sweets among individuals with major depressive episodes. CONCLUSION: Major depressive episodes appear to be linked to lower diet quality in the Brazilian population. Policymakers and public health programs should consider approaches to improve both mental health and dietary habits.