Erectile dysfunction is commonly encountered in diabetic patients and in patients with metabolic syndrome; however, only a few studies have assessed patients with metabolic syndrome and type 2 diabetes mellitus (T2DM) regarding their sexual function. The purpose of this study is to examine the effect of metabolic syndrome and its components on the erectile function of T2DM patients. A cross-sectional study including T2DM patients was conducted from November 2018 until November 2020. Participants were evaluated for the presence of metabolic syndrome and their sexual function was assessed using the International Index of Erectile Function (IIEF) questionnaire. A total of 45 consecutive male patients participated in this study. Metabolic syndrome was diagnosed in 84.4% and erectile dysfunction (ED) in 86.7% of them. Metabolic syndrome was not associated with ED or ED severity. Among metabolic syndrome components, only high-density lipoprotein cholesterol (HDL) was associated with ED [x2(1, n = 45) = 3.894,p= 0.048; OR = 5.5 (95% CI: 0.890–33.99)] and with the IIEF erectile function scores (median 23 vs. 18, U = 75,p= 0.012). Multiple regression analyses showed that HDL was non-significantly associated with the IIEF erectile function scores. In conclusion, among T2DM patients HDL is associated with ED.