Soil heavy metals in karst areas have obvious high background value characteristics. Conducting county-level soil heavy metal ecological risk assessment and identifying heavy metal sources in karst areas are of great significance for soil pollution control and land resource management. Taking Pingguo City, a typical karst county in Guangxi Province, as the study object, 3 151 surface and deep soil samples were collected using the grid method and combined to form 785 analytical samples. The contents of eight heavy metal elements, including As, Cd, Cr, Cu, Hg, Ni, Pb, and Zn, were determined. The content characteristics and sources of heavy metals were analyzed using statistical analysis, interpolation analysis, factor analysis, and the absolute principal component-multiple linear regression model (APCS-MLR). Using the content of heavy metal elements in deep soil (150-200 cm) as background values, the ecological risk assessment of heavy metals in surface soil (0-20 cm) in the study area was conducted using the geo-accumulation index (Igeo) and potential ecological risk index (RI) methods. The results showed that the average content of heavy metal elements in the deep soil of the study area was significantly higher than the background value of the C layer soil in Guangxi Province, and the average content of heavy metal elements in the surface soil was significantly higher than the background value of the A layer soil in Guangxi Province. The spatial distribution of soil heavy metal element content generally showed the characteristics of high in karst areas and low in non-karst areas. The main sources of As, Cr, Ni, Pb, and Zn were soil parent materials, with contribution rates of 74.36%, 84.59%, 93.69%, 79.67%, and 78.17%, respectively. The main sources of Cd were soil parent material sources and unknown sources, with contribution rates of 37.33% and 31.05%, respectively. The main sources of Cu were soil parent materials and unknown sources, with contribution rates of 59.07% and 40.23%, respectively. The main sources of Hg were tectonic activity and mineralization, as well as unknown sources, with contribution rates of 52.49% and 30.65%, respectively. The geo-accumulation index (Igeo) showed that the surface soil was mainly polluted by Cd, with mild or above pollution accounting for 47.78%. The potential ecological risk index (RI) showed that the proportion of surface soil heavy metal comprehensive potential ecological hazards with mild, moderate, strong, and very strong levels was 80.78%, 14.97%, 2.51%, and 1.64%, respectively.