Hepatocellular carcinoma (HCC) is highly aggressive, with delayed diagnosis, poor prognosis, and a lack of comprehensive and accurate prognostic models to assist clinicians. This study aimed to construct an HCC prognosis-related gene signature (HPRGS) and explore its clinical application value. TCGA-LIHC cohort was used for training, and the LIRI-JP cohort and HCC cDNA microarray were used for validation. Machine learning algorithms constructed a prognostic gene label for HCC. Kaplan-Meier (K-M), ROC curve, multiple analyses, algorithms, and online databases were used to analyze differences between high- and low-risk populations. A nomogram was constructed to facilitate clinical application. We identified 119 differential genes based on transcriptome sequencing data from five independent HCC cohorts, and 53 of these genes were associated with overall survival (OS). Using 101 machine learning algorithms, the 10 most prognostic genes were selected. We constructed an HCC HPRGS with four genes (SOCS2, LCAT, ECT2, and TMEM106C). Good predictive performance of the HPRGS was confirmed by ROC, C-index, and K-M curves. Mutation analysis showed significant differences between the low- and high-risk patients. The low-risk group had a higher response to transcatheter arterial chemoembolization (TACE) and immunotherapy. Treatment response of high- and low-risk groups to small-molecule drugs was predicted. Linifanib was a potential drug for high-risk populations. Multivariate analysis confirmed that HPRGS were independent prognostic factors in TCGA-LIHC. A nomogram provided a clinical practice reference. We constructed an HPRGS for HCC, which can accurately predict OS and guide the treatment decisions for patients with HCC.