We develop a dynamic stochastic general equilibrium model with an heterogeneous banking sector. We introduce endogenous default probabilities for both firms and banks, and allow for bank regulation and liquidity injection into the interbank market. Our aim is to understand the interactions between the banking sector and the rest of the economy, as well as the importance of supervisory and monetary authorities to restore financial stability. The model is calibrated against real US data and used for simulations. We show that Basel regulation reduces the steady state but improves the resilience of the economy to shocks, and that moving from Basel I to Basel II is procyclical. We also show that liquidity injections relieve financial instability but have ambiguous effects on output fluctuations.