Primary hepatocellular carcinoma (PHC) is associated with high rates of morbidity and malignancy in China and throughout the world. In clinical practice, a combination of ultrasound and alpha-fetoprotein (AFP) measurement is frequently employed for initial screening. However, the accuracy of this approach often falls short of the desired standard. Consequently, this study aimed to investigate the enhancement of precision of preliminary detection of PHC by ensemble learning techniques. To achieve this, 712 patients with PHC and 1887 healthy controls were enrolled for the assessment of four ensemble learning methods, namely, Random Forest (RF), LightGBM, Xgboost, and Catboost. A total of eleven characteristics, comprising nine serological indices and two demographic indices, were selected from the participants for use in detecting PHC. The findings identified an optimal feature subset consisting of eight features, namely AFP, albumin (ALB), alanine aminotransferase (ALT), platelets (PLT), age, alkaline phosphatase (ALP), hemoglobin (Hb), and body mass index (BMI), that achieved the highest classification accuracy of 96.62%. This emphasizes the importance of the collective use of these features in PHC diagnosis. In conclusion, the results provide evidence that the integration of serological and demographic indices together with ensemble learning models, can contribute to the precision of preliminary diagnosis of PHC.