Findings from clinical trials on the effect of Mg supplementation on depression and anxiety are not generalisable to the community owing to high-dose intervention in short-term periods. Limited observational data are available linking dietary intake of Mg and psychiatric disorders. We aimed to investigate the association between dietary intake of Mg and psychiatric disorders in a large cross-sectional study on Iranian adults. A total of 3172 Iranian adults (with an age range of 18–55 years) were included in this study. Data on dietary intakes were collected using a validated dish-based 106-item semi-quantitative FFQ. To assess depression and anxiety, an Iranian validated version of the Hospital Anxiety and Depression Scale was used. Furthermore, psychological distress was examined using the General Health Questionnaire. The mean age of men and women was 38·4 (sd 8·2) and 35·1 (sd 7·4) years, respectively. In unadjusted analyses, we found that higher dietary Mg intake was associated with lower odds of anxiety among women (OR 0·61; 95 % CI 0·41, 0·90), such that after taking potential confounders into account women in the highest quintile of Mg intake had a 39 % lower odds of anxiety compared with those in the lowest quintile (OR 0·61; 95 % CI 0·40, 0·93). Moreover, deficient Mg intake was positively associated with anxiety among all women (OR 1·80; 95 % CI 1·19, 2·72) and also normal-weight women (OR 1·73; 95 % CI 1·01, 2·95). In addition, a significant inverse association was found between dietary Mg intake and depression among normal-weight men (OR 0·45; 95 % CI 0·20, 0·99) and overweight women (OR 0·45; 95 % CI 0·24, 0·85). In conclusion, dietary intake of Mg was inversely associated with depression and anxiety. However, such findings were not seen for psychological distress.