Due to the utilization of municipal and industrial wastewater, as well as the uncontrolled use of chemical and livestock fertilizers leafy vegetables have a high content of heavy metals (HMs). Soils and eight vegetable samples extensively used in Iran were collected from numerous vegetable farms to investigate the risk of HMs pollution and human health risk in Hamadan province, western Iran. Based on the results, it was found that the tested species differed in the content of HMs. Most of the HMs studied were found to be inside the maximum permissible limits (MPL) except for Cd (1.46–2.40 mg kg−1 DW, for Coriandrum sativum L. (coriander) and Ocimum basilicum L. (basil), respectively and Pb (13.5–21.8 mg kg−1 DW, for Petroselinum crispum (Miller) (parsley) and basil, respectively) which were higher than the MPL. The transfer factor (TF) of HMs in eight vegetables was estimated, and HMs varied greatly between vegetables. The TF values of the studied HMs were ordered based on the mean values of TF in all vegetables: Cd (1.48) > Zn (0.60) > Pb (0.39) > Cu (0.32) > Mn (0.14) > Ni (0.12) > Fe (0.03). The health risk index (HRI) values for the studied HMs for adults were less than 1 except for Cd and Pb. Basil, Mentha piperita L. (peppermint), and Anethum graveolens L. (dill) were chosen as high accumulators of Cd and Pb based on TF and HRI. The health risks connected with the Cd and Pb content of vegetables cultivated in western Iran are highlighted in this study, which implies that required steps should be done to reduce Cd and Pb accumulation in western Iran's vegetables.