Vegetables cultivated near roads absorb toxic metals from polluted soil, which enter the human body through the food chain and cause serious health problems to humans. The present study investigated the concentration of lead (Pb) and nickel (Ni) in soils and vegetables grown along the roadside of District Swat, Pakistan, and the health risks associated with the consumption of the tested vegetables. In results, Pb concentration was higher in plants located at the distance between 0–10 m away from the roadside than the WHO permissible limit. In such plants, Pb concentration was higher than Ni. Rumex dentatus contained the highest concentration of Pb (75.63 mg kg−1 DW) among the tested vegetables while Ni concentration (27.57 mg kg−1 DW) was highest in Trachyspermum ammi as compared to other plants. Concentration and accumulation of both the metals decreased in soil and plants with increasing distance from the road. Similarly, target hazard quotient values noted for Pb (up to 3.37) were greater than unity, which shows that there is a potential risk associated with the consumption of tested vegetables near the road. Moreover, the values of target cancer risk (up to 0.8413) were greater than 0.0001, which shows that there is a risk of cancer with the consumption of tested vegetables. In conclusion, the consumption of tested vegetables was very dangerous as it may lead to higher risks of cancer. Strict regulatory control is recommended on the cultivation of these vegetables along the roadside to avoid any contamination due to roadside exhaust.