The concentration of risk within the financial system leads to systemic instability. We propose a theory to explain the structure of the financial system and show how it alters the risk-taking incentives of financial institutions when the government optimally intervenes during crises. By issuing interbank claims, risky institutions endogenously become large and interconnected. This concentrated structure enables institutions to share the risk of systemic crises in a privately optimal way but leads to excessive risk taking even by peripheral institutions. Interconnectedness and excessive risk taking reinforce one another. Macroprudential regulation that limits the interconnectedness of risky institutions improves welfare. (JEL D82, E44, G01, G21, G28)