Changes in crop types and long-term monoculture substantially impact soil microbial communities. Exploring these changes and their influencing factors is of great significance for addressing the challenges posed by continuous cropping. Soil surface layer samples from greenhouse tomatoes fields cultivated for 5 (Y5), 9 (Y9), 13 years (Y13), and a surrounding corn field (CK) as a control were analyzed. The Y13 sample showed a significant increase in the relative abundance of Pseudomonadota (43.1%) and a decrease in Actinobacteria (50.3%) compared to the CK sample. Soil bacterial alpha diversity generally declined from the CK to Y13 (0.1–22.2%) sample, with a small peak in Y9 for Chao1 and Observed_species. Significant differences in Chao1 and Observed_ species were observed between the CK and Y13 samples. Beta diversity analysis revealed a pronounced variation in soil bacterial community structure across planting years, with the divergence from the CK sample intensifying over time. In comparison to the Y5 vs. CK samples, Y9 and Y13 exhibited marked differences from the CK across the same and broader metabolic pathways, suggesting a potential convergence of microbial activities over time. The Y9 and Y13 samples showed significantly higher biosynthesis abundance (7.50% and 6.36%, respectively) than the CK. In terms of soil physicochemical indices, the carbon–nitrogen ratio was the primary factor influencing soil bacterial composition. In conclusion, we found that crop alteration and continued planting changed the soil’s bacterial composition and increasing planting years suppressed the soil’s bacterial diversity, leading to a stable bacterial ecology after nine years. Implementing appropriate measures during this critical period is vital for optimal soil utilization.