Health and longevity are common human goals, and environmental factors can have significant impacts on human health. This study aims to investigate the historical changes and sources of trace elements in the sediments of a typical karstic river basin with high longevity population in Hechi City, Guangxi, China and to evaluate the ecological risks of trace elements in sediments. The results showed that over the past 100 years, the contents of trace elements in the sediments were lower in the upper reaches than in the middle and lower reaches of the river. The sediments had high trace element contents in 1950-1959 and 1989-1998, while low contents appeared after 1998. These periods correspond to China's industrial growth in the early 1950s, the Great Leap Forward movement in the late 1950s, the reform and opening-up policy implemented in the 1980s-1990s and the environmental protection policies to strengthen pollution control that have been implemented since 2000. Limestone soil and carbonate rock are the main sources of sediment in the basin. Although the geological background values of Cd and other trace elements in the basin were relatively high, the high calcium content and alkalinity of the water and sediment in the basin reduced the bioavailability of Cd and other heavy metals. The mainstream of Panyang River had a low environmental risk, but the tributary Bama River where there is dense population poses a moderate risk.