We study optimal bailout policies in the presence of banking and sovereign crises. First, we use European data to document that asset guarantees are the most prevalent way in which sovereigns intervene during banking crises. Then, we build a model of sovereign borrowing with limited commitment, where domestic banks hold government debt and also provide credit to the private sector. Shocks to bank capital can trigger banking crises, with government sometimes finding it optimal to extend guarantees over bank assets. This leads to a trade-off: Larger bailouts relax domestic financial frictions and increase output, but also imply increasing government fiscal needs and possible heightened default risk (i.e., they create a 'diabolic loop'). We find that the optimal bailouts exhibit clear properties. Other things equal, the fraction of banking losses that the bailouts would cover is: (i) decreasing in the level of government debt; (ii) increasing in aggregate productivity; and (iii) increasing in the severity of the banking crisis. Even though bailouts mitigate the adverse effects of banking crises, we find that the economy is ex ante better off without bailouts: the 'diabolic loop' they create is too costly.