We analyze monetary policy in a New Keynesian model with heterogeneous firms and financial frictions. Firms differ in their productivity and net worth and face collateral constraints that cause capital misallocation. TFP endoge- nously depends on the time-varying distribution of firms. Although a reduction in real rates increases misallocation in partial equilibrium, general-equilibrium effects overturn this result around: a monetary expansion increases the invest- ment of high-productivity firms relatively more than that of low-productivity ones, crowding out the latter and increasing TFP. We provide empirical evidence based on Spanish granular data supporting this mechanism. This has important im- plications for optimal monetary policy. We show how a central bank without pre-commitments engineers an unexpected monetary expansion to increase TFP in the medium run. In the event of a cost-push shock, the central bank leans with the wind to increase demand and reduce misallocation.