Objective:To investigate the association among social determinants, lifestyle variables and diet quality in São Paulo, Brazil.Design:Cross-sectional study, 2015 Health Survey of São Paulo (Inquérito de Saúde de São Paulo (2015 ISA-Capital)) with Focus on Nutrition Study (2015 ISA-Nutrition).Setting:Population-based study, with a representative sample of adults living in São Paulo, Brazil.Participants:Adults (aged 20–59 years, n 643) and older adults (aged ≥60 years, n 545).Results:We observed differences in the Brazilian Healthy Eating Index-Revised (BHEI-R) by education, income, occupation, sex and race. Whole grains (0·63 points, 12·6 % of the maximum score), sodium (2·50 points, 25·0 %) and solid fat, alcohol and added sugars (9·28 points, 46·4 %) components had the lowest BHEI-R scores. Factors positively associated with diet quality included the presence of one disease or more (e.g. diabetes mellitus, hypertension, cancer, hypercholesterolaemia: β = 0·636, P < 0·001), income (middle income: β = 0·478, P < 0·001; high income: β = 0·966, P < 0·001) and occupation (other: β = 1·418, P < 0·001). Energy (β = –0·001, P < 0·001), alcohol consumption (β = –0·207, P = 0·027), education level (middle education: β = –0·975, P < 0·001; high education: β = –1·376, P < 0·001), races other than white (β = –0·366, P < 0·001) and being unemployed (β = –0·369, P < 0·046) were negatively associated with diet quality.Conclusions:Groups affected by socio-economic inequalities need better diet quality. Governmental actions should be implemented to reduce the consumption of energy-dense and sodium-rich foods, facilitate access and information on healthy eating, and conduct nutritional education.