Analyzing the cause is crucial for recognizing the risks associated with potentially harmful substances found in soil, such as toxic elements. These substances can have adverse effects on both the ecological environment and human health, as they can migrate and transform within food chain networks. Therefore, it is imperative to address and prioritize the risks associated with these elements. Dongdagou, Baiyin City, Gansu Province, is a typical area of potentially toxic element pollution in farmland soil, which has attracted much attention and urgently needs to be controlled. Therefore, the main objective of this investigation is to analyze the concentrations of As, Cd, Pb, Hg, Cu, and Zn in the agricultural soil found in Dongdagou. Using statistical analysis, ecological and human health risk, principal component analysis, and the PMF model, we found that (1) there are varying degrees of accumulation in the soil in the study area, with Cu being the main component. (2) The soil in the study area has high and extremely high concentrations of Cd, posing significant risks. On the other hand, Hg presents mild and medium risks. However, there are no risks associated with As, Pb, Cu, and Zn. Overall, the ecological risks in the study area’s soil due to potentially toxic elements are predominantly extremely high (49.65%) and high (38.25%). A small proportion of the soil exhibits low risks (2.76%) and medium risks (9.33%). (3) As has a moderate acceptable carcinogenic risk for local residents, Cd has a moderate acceptable carcinogenic risk for local children, and other potentially toxic elements do not have carcinogenic or non-carcinogenic risks. (4) The source analysis shows that Cd in the soil in the study area mainly comes from agricultural activities and sewage irrigation, As mainly comes from industrial production, and Zn, Cu, Pb, and Hg are multiple sources. We recommend adopting targeted and differentiated safety utilization and control measures based on the pollution level and potential risks of potentially toxic elements in the research area, combined with the sources of potentially toxic elements.