Heavy metal pollution has become one of the most important threats that can endanger the health of animals, the environment, and humans. The present study was performed to investigate the potential ecological risk (PER) of heavy metals [zinc (Zn), copper (Cu), cobalt (Co), molybdenum (Mo), manganese (Mn), and selenium (Se)] in the coastal soils of southwest Iran in 2019. The samples were collected from six soil sites and three depth intervals (0–15, 15–30, and 30–45 cm) among bare and vegetated coastal soils. The soil samples to study the soil properties (soil grain size, pH, EC, and soil organic carbon) and metal contamination were taken from soil (36 samples), water (6 samples), and plants (24 samples). The soil ecological risk (ER), the pollution load index (PLI), contamination degree (Cdeg), modified contamination degree (mCdeg) for heavy metal contamination in the soil, and enrichment factor (EF index) indicate the origin of metals entering the environment, and hence these parameters were investigated. The results of this study showed that the levels of Zn, Cu, Co, Mn, Se, and Mo were in the range of low-risk contaminants in this region. According to the results of the study, the risk index (RI) for metals was in the range of 1.296–3.845, which is much lower than 150, and therefore the ecological risk potential calculated in this study was in the low-risk category for toxic elements. Based on the results, it was found that agricultural, industrial, and human activities played an effective role in the accumulation of Zn, Cu, Co, Se, and Mo in the soil. In addition, the main source of Mn metal is believed to be natural due to geological activities in the region.