Background: Hepatocellular carcinoma (HCC) is one of the most malignant cancers and has a poor prognosis. The immune microenvironment is closely related to the drug sensitivity of a tumor. Necroptosis was reported to be a key factor for HCC. The prognostic value of necroptosis-related genes and their association with the tumor immune microenvironment are still unknown. Methods: Necroptosis-related genes that could comprise a signature for predicting the prognosis of HCC cases were identified using univariate analysis and least absolute shrinkage and selection operator Cox regression analysis. The association between this prognosis prediction signature and HCC immune microenvironment was analyzed. The immunological activities and drug sensitivities were compared between different risk score groups identified using the prognosis prediction signature. The expression levels of the five genes comprising the signature were validated using RT-qPCR. Results: A prognosis prediction signature consisting of five necroptosis-related genes was constructed and validated. Its risk score was = (0.1634 × PGAM5 expression) + (0.0134 × CXCL1 expression) - (0.1007 × ALDH2 expression) + (0.2351 × EZH2 expression) - (0.0564 × NDRG2 expression). The signature was found to be significantly associated with the infiltration of B cells, CD4+ T cells, neutrophils, macrophages, and myeloid dendritic cells into the HCC immune microenvironment. The number of infiltrating immune cells and the expression levels of immune checkpoints in the immune microenvironment of high-risk score patients were higher. Sorafenib and immune checkpoint blockade were determined to be ideally suited for treating high-risk score patients and low-risk score patients, respectively. Finally, RT-qPCR results confirmed that the expression levels of EZH2, NDRG2, and ALDH2 were significantly down-regulated in HuH7 and HepG2 cells compared to those in LO2 cells. Conclusion: The necroptosis-related gene signature developed herein can classify patients with HCC according to prognosis risk well and is associated with infiltration of immune cells into the tumor immune microenvironment.