Excessive leverage, i.e. the abuse of debt financing, is considered one of the primary factors in the default of financial institutions. Systemic risk results from correlations between individual default probabilities that cannot be considered independent. Based on the structural framework by Merton (1974), we discuss a model in which these correlations arise from overlaps in banks' portfolios. Portfolio diversification is used as a strategy to mitigate losses from investments in risky projects. We calculate an optimal level of diversification that has to be reached for a given level of excessive leverage to still mitigate an increase in systemic risk. In our model, this optimal diversification further depends on the market size and the market conditions (e.g. volatility). It allows to distinguish between a safe regime, in which excessive leverage does not result in an increase of systemic risk, and a risky regime, in which excessive leverage cannot be mitigated leading to an increased systemic risk. Our results are of relevance for financial regulators.