Mangrove forests are one of the most productive and seriously threatened ecosystems in the world. The widespread invasion of Spartina alterniflora has seriously imperiled the security of mangroves as well as coastal mudflat ecosystems. Based on a model evaluation index, we selected RF, GBM, and GLM as a predictive model for building a high-precision ensemble model. We used the species occurrence records combined with bioclimate, sea–land topography, and marine environmental factors to predict the potentially suitable habitats of mangrove forests and the potentially suitable invasive habitats of S. alterniflora in the southeastern coast of China. We then applied the invasion risk index (IRI) to assess the risk that S. alterniflora would invade mangrove forests. The results show that the suitable habitats for mangrove forests are mainly distributed along the coastal provinces of Guangdong, Hainan, and the eastern coast of Guangxi. The suitable invasive habitats for S. alterniflora are mainly distributed along the coast of Zhejiang, Fujian, and relatively less in the southern provinces. The high-risk areas for S. alterniflora invasion of mangrove forests are concentrated in Zhejiang and Fujian. Bioclimate variables are the most important variables affecting the survival and distribution of mangrove forests and S. alterniflora. Among them, temperature is the most important environmental variable determining the large-scale distribution of mangrove forests. Meanwhile, S. alterniflora is more sensitive to precipitation than temperature. Our results can provide scientific insights and references for mangrove forest conservation and control of S. alterniflora.