Patients with heart failure (HF) were compared with non-HF people to explore the relationship between the triglyceride glucose (TyG) index and HF in participants with cardiovascular and cerebrovascular diseases. TyG index was calculated as ln [fasting triglyceride (mg/dL) × fasting glucose (mg/dL)/2]. Multivariate logistic regression models were used to investigate the association between the TyG index and the risk of HF. Restricted cubic spline (RCS) analysis was applied to evaluate the dose-response relationship between the TyG index and the risk of HF. National Health and Nutrition Examination Survey (NHANES) (2007-2018) was used to analyze the association between TyG and HF in patients. A total of 13,825 participants who had their TyG index measured were included, involving 435 individuals with HF and 13,390 individuals without HF. Those with HF had higher levels of the TyG index compared with those without HF (8.91 ± 0.74 vs. 8.57 ± 0.66, p < 0.001). The odds ratio (OR) of HF for the TyG index from logistic regression was 1.644 and 1.057 in Model 1 (without adjusting for any variables) and Model 4 (adjusted for all covariates), respectively. Compared with individuals with Q1, a higher TyG index was related to the increased risk of HF. Model 1 showed that there was a linear dose-response relationship between the TyG index and HF (p = 0.686). The TyG index predicted the area of the receiver operating characteristic (ROC) curve of 0.602 (95% CI: 0.575-0.629, p < 0.001) and the optimal cutoff value was 8.91. The TyG index was positively associated with the risk of HF. The TyG index may be a therapeutic target and an important predictor of HF.