Pro-environmental behavior can promote the optimization of the living environment and sustainable social development. This paper constructs a theoretical analysis framework of “environmental consciousness, habitat environment-social capital- pro-environmental behavior”. By using structural equation modeling and 1005 instances of microscopic research data, we analyzed the influence of environmental awareness and habitat environment on the pro-environmental behavior of community residents. The results of the analysis were combined with the Bootstrap method to verify the mediating role of social capital dimensions in the influence of environmental awareness and habitat quality on the pro-environmental behavior of community residents. The results show that: Firstly, environmental awareness, habitat quality, and social capital have positive effects on the pro-environmental behavior of community residents. Secondly, environmental awareness and habitat quality have positive effects on the five dimensions of social capital. Thirdly, among the five dimensions of social capital, four dimensions of social trust, social norms, sense of community belonging, and community voluntarism play a partially mediating role between environmental awareness, habitat quality, and pro-environmental behavior. This paper enriches the research on the influence of environmental awareness and habitat environment on pro-environmental behavior, reveals the mediating effect of each dimension of social capital, and broadens the horizon for the study of pro-environmental behavior. The results of the study can provide a reference for decision making to promote the implementation of pro-environmental behavior among community residents.