We study the causal impact of patent invalidation on subsequent innovation and exit by the patent holder. The analysis is based on patent litigation at the U.S. Court of Appeals for the Federal Circuit, and exploits the random allocation of judges to control for endogeneity of the judicial decision. Invalidation causes the patent holder to reduce subsequent patenting over a five-year window by 50 percent on average, but the effect is heterogeneous. The impact is large for small and medium-sized firms, particularly in technology fields where they face many large competitors, and for patents central to their technology portfolio. We find no significant effect for large firms. Invalidation also significantly increases the likelihood that small firms exit from patenting entirely.