Building on the trade-o¤ between agency costs and monitoring costs, we develop a dynamic theory of optimal capital structure with …nancial distress and reorganization. Costly monitoring eliminates the agency friction and thus the risk of ine¢ cient liquidation. Our key assumption is that monitoring cannot be applied instantaneously. Rather, transitions between agency and monitoring are subject to search frictions. In the optimal contract, the …rm seeks a monitoring opportunity whenever it is …nancially distressed, i.e., when the risk of liquidation is high. If a monitoring opportunity arrives in time, the manager is dismissed, the capital structure is reorganized as in Chapter 11 bankruptcy, and the search for a new manager begins. In agency, an optimal capital structure consists of equity, long-term debt, contingent long-term debt, and a credit line with performance pricing. In …nancial distress, coupon payments to contingent debt are suspended but the interest rate on the credit line is stepped-up, which gives the …rm simultaneously debt relief and a steep incentive to improve its …nancial position. An episode of distress can end with …nancial recovery, transition to bankruptcy reorganization, or liquidation.