Although second language (L2) engagement has received increasing attention, L2 writing engagement has been rarely investigated. Based on the social-cognitive theory, environmental sources could influence individuals’ motivations which in turn affect their engagement. However, factors contributing to L2 writing engagement have not been thoroughly understood. The present study investigated the associations between three dimensions of classroom environment (teacher support, student cohesion, and task orientation) and L2 writing engagement as well as the mediation roles of mastery and performance approach goals among 721 Chinese learners of English as a foreign language (EFL). Structural equation model analysis suggested that task orientation was the most influential environmental factor; it could not only directly influence EFL writing engagement, but could also indirectly influence it through mastery and performance goals. Teacher support could only indirectly influence engagement through mastery and performance goals. With dimensions of EFL writing engagement disentangled, teacher support negatively predicted agentic engagement but not the other three dimensions. However, mastery and performance goals fully mediated the path from teacher support to behavioral, emotional, and cognitive engagement. Task orientation had positive effects on all aspects of writing engagement and most of the effects could be carried by the two types of goal orientations. Implications and future directions are also discussed.