Sedimentary pyrite has long been used as an archive of marine environments in Earth history. To capture reliable paleoenvironmental signals, however, we need to first evaluate pyrite in sedimentary strata as it can be altered and masked by later diagenetic and/or hydrothermal processes. Here, we trained two supervised machine learning algorithms on a large LA-ICP-MS pyrite trace element database to distinguish pyrite of different origins. The analysis validates that two models built on the co-behavior of 12 trace elements (Co, Ni, Cu, Zn, As, Mo, Ag, Sb, Te, Au, Tl, and Pb) can be used to accurately predict pyrite origins. Further statistical analysis suggests four trace element clusters behaving differently among sedimentary (syngenetic and early diagenetic), synsedimentary hydrothermal (syngenetic hydrothermal), and post-sedimentary hydrothermal (epigenetic hydrothermal) pyrite, which is probably driven by chemical and physical properties of source fluids, interactions between elements, competition among coprecipitating minerals, and pyrite growth rate. Armed with this initial success and aided by new LA-ICP-MS trace element data from 9 samples, we then demonstrated the efficacy of this approach in identifying the origins of pyrite from two Neoproterozoic sedimentary successions in South China. The first set of samples contain isotopically superheavy pyrite (i.e., whose bulk-sample δ34S values greater than those of contemporaneous seawater sulfate and whose origins remain controversial) from the Cryogenian Tiesi’ao and Datangpo formations. The second set of samples contain pyritic rims (associated with fossiliferous chert nodules and thought to be critical in exceptional fossil preservation) from the Ediacaran Doushantuo Formation. For the superheavy pyrite, the models consistently show high confidence levels (mostly > 80 % probability) in identifying its genesis type, and three out of four samples were given sedimentary origins. For the pyritic nodule rims, the models suggest that early diagenetic pyrite was subsequently altered by hydrothermal fluids and therefore shows mixed signals. The study highlights the importance of pyrite trace elements in deciphering and distinguishing the origins of pyrite in sedimentary strata.