Prior research has demonstrated that erectile dysfunction (ED) is a significant risk factor for cardiovascular disease (CVD) and premature mortality. Few studies have examined the link between ED and hyperglycemia, and the predictive power of ED for mortality in individuals with hyperglycemia. A cohort of 1584 adults diagnosed with hyperglycemia, consisting of 583 individuals with diabetes and 1001 individuals with prediabetes, was selected from the National Health and Nutrition Examination Survey (NHANES) conducted between 2001 and 2004. The study found a positive correlation between severe ED and hyperglycemia (OR, 2.03; 95% CI 1.53–2.68), while no significant relationship was observed between severe ED and CVD events (OR, 1.60; 95% CI 0.91–2.80). Additionally, no statistical association was found between diabetes or prediabetes status and ED. After multivariable adjustments, severe ED was found to be significantly associated with an increased risk of all-cause mortality (HR, 1.67; 95% CI 1.16–2.39), while no significant association was observed between severe ED and CVD mortality (HR, 1.92; 95% CI 0.92–3.98). Our study indicates a significant correlation between ED and hyperglycemia status. Hyperglycemia Individuals with ED generally exhibited an unfavorable prognosis for mortality due to all causes and CVD, particularly among those with low levels of physical activity.