Erectile dysfunction (ED) is related to nutritional and inflammatory factors. The hemoglobin, albumin, lymphocyte, and platelet score (HALP), a new index reflecting the nutritional and inflammatory status, has been associated with a higher risk of diabetic retinopathy, particularly at lower values (≤ 42.9). However, studies focusing on the relationship between HALP and ED risk are scarce. Hence, this study aimed to investigate the association between HALP and ED. Data were extracted from the National Health and Nutrition Examination Survey (NHANES) conducted between 2001 and 2004. Based on self-reported data, participants were classified into either the ED group or the non-ED group. Next, the HALP score was categorized into four quartiles (Q1–4). Weighted multivariate regression analysis was performed to assess the relationship between categorical HALP and ED risk. Additionally, restricted cubic spline (RCS) analysis was conducted to examine the association between continuous HALP scores and ED risk. Furthermore, subgroup analyses were conducted to examine the association between categorical HALP and the risk of ED based on age, as well as the status of hypertension, diabetes and cardiovascular disease. Finally, a mediation analysis was carried out to investigate the mediating effect of HALP and related parameters on the association between urinary cobalt levels and ED. Initially, the data of 21,161 participants were collected. After implementing the inclusion and exclusion criteria, 3406 participants were included in the final analyses. Weighted multivariate regression analysis demonstrated that the Q4 HALP group was associated with a lower risk of ED (OR 0.96, 95% confidence intervals 0.92–1.00, P = 0.037). Meanwhile, RCS analysis showed that HALP was nonlinearly associated with the risk of ED. In addition, subgroup analyses demonstrated that participants in the Q3/4 HALP group had a significantly lower ED risk than those in the Q1 group among patients aged ≥ 50 years, as well as those with hypertension and diabetes. Lastly, mediation analysis revealed that HALP and its associated parameters had a marginal average causal mediation effect on the relationship between urinary cobalt levels and ED risk (P > 0.05). In US adults, high HALP scores were correlated with a lower risk of ED. The relationship was more pronounced in participants aged ≥ 50 years with hypertension and diabetes. Furthermore, HALP and its parameters may not mediate the association between urinary cobalt levels and ED risk.