Cooperative innovation is an effective strategy for enterprises to obtain innovation resources and reduce innovation costs. However, existing studies have paid less attention to why and when enterprises choose cooperative innovation strategies. Focusing on market competition as a salient feature of the task environment, this study explores the mechanisms through which it affects cooperative innovation. Using a sample of leading manufacturing enterprises in China between 2010 and 2018, we adopt a negative binomial model to test our hypotheses. The results show that market competition has a U-shaped relationship with cooperative innovation breadth and cooperative innovation depth. And the relationship between market competition and cooperative innovation is moderated by the institutional environment factors. Specifically, the main effect is negatively moderated by intellectual property protection. And government subsidies only have significant moderating effects on the relationship between market competition and cooperative innovation breadth, but no significant moderating effects on the relationship between market competition and cooperative innovation depth. Besides, revealing the aforementioned relationship, this study provides theoretical and practical implications on how to strike a balance between innovation resources acquisition from the external partners and the associated risks of cooperation.