Background: Inflammatory responses have drawn more attention to atherosclerosis; however, the immune-related genes (IRGs) as a prognostic factor in atherosclerotic plaque remain to be fully elucidated. Here, the purpose of this study was to investigate whether the IRGs could be identified as a reliable biomarker for predicting ischemic events in patients undergoing carotid endarterectomy (CEA). Methods: Two datasets GSE97210 and GSE21545 were downloaded from the Gene Expression Omnibus (GEO) database. The dataset GSE97210 was used to explore the significant pathways and differentially expressed IRGs (DEIRGs) between plaques and controls, which were further screened to identify the prognostic DEIRGs in the GSE21545 dataset. The identification of molecular subgroups with the prognostic gene expression patterns was achieved through nonnegative matrix factorization (NMF) clustering. Functional analyses including GO, KEGG, GSVA, and GSEA analyses, and immune analyses including xCell and ssGSEA algorithms were conducted to elucidate the underlying mechanisms. The prognostic risk model was constructed using the LASSO algorithm and multivariate Cox regression analysis. Results: A total of 796 DEIRGs (including 588 upregulated and 208 downregulated) were identified. Nine prognostic DEIRGs were further screened with univariate Cox regression analysis. Two clusters with different prognosis were grouped based on the prognostic DEIRGs. Immune infiltration analysis shows that cluster 2 with a better prognosis presented with a higher immune response than cluster 1. A prognostic model based on seven IRGs (IL2RA, NR4A2, DES, ERAP2, SLPI, RASGRP1, and AGTR2) was developed and verified. Consistent with the immune analysis of the cluster, the immune infiltration in the low-risk group with a better prognosis was also more active than that in the high-risk group. Finally, a nomogram based on the seven genes was constructed, which might have future implications in clinical care. Conclusion: The expression of immune-related genes is correlated with the immune microenvironment of atherosclerotic patients and could be applied to predict the ischemic events in patients undergoing CEA accurately.