Background: The antitumor immune response may play a major role in the clinical outcome of hepatocellular carcinoma (HCC). We characterized the liver immune microenvironment by direct hybridization of RNA extracted from HCC and nontumorous tissues. Methods: RNA was extracted from frozen liver tissue samples of HCC (T; n = 30) and nontumorous tissues (NT; n = 33) obtained from 38 patients. Matched samples were available for 25 patients. The immune gene expression profile was analyzed with the nCounter GX Human Immunology v2 system (NanoString Technologies), which detects the expression levels of 579 immune response-related genes simultaneously. Results: Since the immune gene expression profile of T and NT tissues was significantly different, the prognostic relevance of the liver immune microenvironment was evaluated in the T and NT samples separately. Unsupervised clustering detected two main clusters of immune gene expression both in T and in NT liver samples. In both cases, the expression clusters identified groups of patients with a significantly different median time to HCC recurrence (TTR) but similar overall survival. Based on T tissue, two groups with median TTR of 19 and 127 months, respectively, were detected (p < 0.005). Expression of genes related to T-cell activation was associated with longer TTR. The analysis of NT tissue discriminated subsets of patients with median TTR of 22 and 68 months (p < 0.05). In contrast to T tissue, a predominant inflammatory immune environment was associated with shorter TTR. Conclusions: Immune gene expression profiles predictive of TTR could be identified both in HCC and in adjacent cirrhotic tissues. Longer TTR was associated with overexpression in T tissue and downregulation in NT tissue of the immune response and of inflammation-related genes.