The present study aimed to explore the clinical efficacy and safety of hydromorphone combined with sufentanil in patient-controlled intravenous analgesia (PCIA) for patients with hepatocellular carcinoma (HCC) and its effect on serum immune factors in serum. Data from 385 patients with HCC, admitted to the Hunan Provincial People's Hospital (Changsha, China) from February 2015 to September 2018, were retrospectively analyzed. Laparoscopic hepatectomy was performed in all patients. A total of 180 patients who received PCIA were treated with sufentanil (control group), and 205 patients who received PCIA were treated with hydromorphone and sufentanil (study group). PCIA was used after hepatocellular cancer operation. In the control group, the analgesic pump was filled with sufentanil (2 µg/kg) and tropisetron (5 mg), whereas in the study group, the analgesic pump was filled with sufentanil (2 µg/kg), tropisetron (5 mg) and hydromorphone (5 mg). Both groups of drugs were diluted into 100 ml with normal saline and the loading dose was 5 ml; the continuous dose was 2 ml/h and the single PCIA amount was 2 ml. The visual analogue scale (VAS) and numeric sedation scale (NSS) scores at 12 and 24 h after operation, as well as and satisfaction score at 24 h after operation, were recorded. The levels of CD3 + , CD4 + , CD8 + lymphocytes and NK cells in the peripheral blood of patients were detected by flow cytometry. The postoperative hospitalization time, first flatulence time, first defecation time and first ambulation time, as well as the adverse reactions, were recorded. The results revealed that the satisfaction score of the patients at 24 h after operation was significantly higher in the study group than that in the control group (P<0.05). Additionally, there were no serious adverse reactions in either group. In conclusion, PCIA with hydromorphone and sufentanil can provide safe and effective analgesia, may improve the levels of immune factors and enhance the recovery ability of the patients.