Background: Nowadays, uncontrolled use of chemical fertilizers in agriculture is one of the reasons for the entry of heavy metals into the environment. In this study, the heavy metals contamination of the soils enriched with compost and chemical fertilizers in the North of Iran and its ecological risk assessment were evaluated. Methods: In this study, 108 soil samples were collected from agricultural soils of some places of Babol in Mazandaran province. An atomic absorption spectrophotometer (PG-990) was used to determine the concentrations of lead, cadmium, and zinc in the soil samples. The assessment of soil contamination was performed by the contamination factor, degree of contamination indices, and the potential ecological risk of the heavy metals. Data were analyzed using SPSS version 22. Descriptive and chi-square tests were used to compare the mean with existing standards. Significant level was considered at P<0.05. Results: The highest lead concentration (35.7 ± 9.5 mg/kg) was observed at 5-cm depth, and the maximum cadmium (1.1 ± 0.2 mg/kg) and zinc (88 ± 22.6 mg/kg) concentrations were observed at 15-cm depth. The results showed that lead, cadmium, and zinc concentrations in the agricultural soils enriched with compost fertilizers were acceptable, but agricultural soils enriched with chemical fertilizers indicated higher content than those enriched with compost fertilizers and higher than the maximum allowable concentration. The maximum contamination degree, pollution index, and potential ecological risk in the agricultural soils enriched with the chemical fertilizers were 15.77, 1.97, and 293.48, respectively, and these soils had low potential pollution and moderate ecological risks. Conclusion: According to the results, it is necessary to use compost fertilizers for the agricultural soils enrichment.