This paper studies systemic risk in the interbank market. We first establish that in the German interbank lending market, a few large banks intermediate funding flows between many smaller periphery banks. We then develop a network model in which banks trade off the costs and benefits of link formation to explain these patterns. The model is structurally estimated using banks' preferences as revealed by the observed network structure before the 2008 financial crisis. The model describes why the interbank intermediation arrangement arises, estimates the frictions underlying the arrangement, and quantifies how shocks are transmitted across the network. In out-of-sample tests, model estimates based on pre-crisis data successfully predict changes in the network structure and lending to firms during the 2008 financial crisis. Finally, for each of the intermediaries, we quantify systemic risk and the impact of ECB funding in reducing this risk.