Adolescence is a key period for consolidating heathy lifestyles and proper eating habits that can last into adulthood. To analyze the diet quality of Spanish adolescents and its association with socioeconomic factors and health behaviors by gender, a cross-sectional study was conducted using data from the DESKcohort project, consisting of a biannual panel survey on health, health behaviors, and associated determinants, collected in secondary education centers. The study population consisted of 7319 students aged 12 to 18 years. Data were collected from October 2019 to March 2020. The dependent variable was diet quality score according to the Spanish adaptation of the Healthy Eating Index (S-HEI). The independent variables included were socioeconomic factors and health behaviors. We conducted linear regression separately by gender. Diet quality score was significantly higher for girls than for boys (68 and 65, respectively, p < 0.001). For both genders, poorer diet quality was associated with a low level of physical activity [−0.9 (95% CI = −1.6:−0.2) in boys, −1.2 (95% CI = −1.9:−0.4) in girls], alcohol use [−2.5 (95% CI = −3.7:−1.3) in boys, −1.0 (95% CI = −1.9:0.0) in girls], poor self-perceived health [−1.1 (95% CI = −2.4:0.2) in boys, −3.5 (95% CI = −4.6:−2.4) in girls], and having attended Intermediate Level Training Cycles [−2.9 (95% CI = −4.3:−1.5) in boys, −1.9 (95% CI = −3.5:−0.3) in girls]. In girls, poorer diet quality also was associated with low mood [−1.1 (95% CI = −1.9:−0.3)]. The variance was 9% in boys and 12% in girls. Our results highlight the need to consider socioeconomic and health-related factors, as well as gender, when conducting interventions to promote healthy eating among adolescents.