IntroductionWith urbanization and industrialization in the developing world, urban and peri-urban agriculture is increasingly contributing to urban food systems, employment, and income generation opportunities. However, urbanization and industrialization may release harmful pollutants, including heavy metals and trace elements into agricultural soils, posing ecological, environmental and public health concerns. This paper assessed the potential risks of soil contamination with heavy metals and trace elements in peri-urban farmlands in Nairobi city catchment in Kenya. MethodsA total of 60 soil samples were collected from ten vegetable farming zones (S1-S10) and processed following standard protocols. The concentrations of As, Cd, Co, Cr, Cu, Fe, Hg, Mn, Ni, Pb, V and Zn were analyzed in the samples using inductively coupled plasma-mass spectrometry (ICP-MS). Results and discussionResults revealed that the soil samples have elevated concentrations of As, Cd, Co, Cr, Cu, Fe, Hg, Mn, Ni, Pb, V and Zn, with some elements including As (1.7%), Cd (13.3%), Mn (80%), Pb (1.7%) and Zn (11.7%) exceeding the permissible thresholds for agricultural soils. The spatial distribution of the elements exhibited three similar distribution patterns with slight variations between the hotspot sites of the different elements: (i) Co and Mn, (ii) Cu and Cr and (iii) As, Cd, Fe, Hg, Pb and Zn, while Ni and V exhibited singular spatial distributions compared to other elements. Elements such as As, Cd, Co, Fe, Hg, Mn, Pb and Zn appeared to be of anthropogenic enrichment, while Cr, Cu, Ni and V appeared to originate mainly from lithogenic and natural sources. The elements As, Cd, Hg and Pb exhibited high ecological risks, with Cd contributing about 46-66% of the overall ecological risk. The sampling sites S1, S5, S7, S9 and S10 depicted the highest ecological risks of 145, 103, 146, 121 and 146, respectively. The findings call for proper zoning of suitable agricultural areas and sound waste management protocols in urban and peri-urban landscapes. Further, remediation of contaminated soils and farmers’ sensitization are recommended for ecological and public health risk alleviation.