This paper investigates whether corporate social responsibility (CSR) can constrain real activities earnings management (REM), focusing on the legitimacy pressures of CSR compliance in the Chinese context. The distinctive setting of the role of government in CSR allow us to draw new inference. We find that contrary to the criticism that mandated CSR policies is simply window dressing, strong CSR performers are more ethical in their reporting behaviors because they have incentives to maintain good relationship with stakeholders. However, the relationship is weaker for state-owned enterprises (SOEs), which suggests that SOEs tend to engage CSR to shape perceptions of their political legitimacy. Due to their lower level of managerial discretion over CSR activities, managers of SOEs tend to use CSR as their entrenchment strategy. Our results are also robust when controlling for the endogeneity of CSR.