This paper studies the implications of cross-border financial integration for financial stability when banks' loan portfolios adjust endogenously. Banks can be subject to sectoral and aggregate domestic shocks. After integration they can share these risks in a complete interbank market. When banks have a comparative advantage in providing credit to certain industries, financial integration may induce banks to specialize in lending. An enhanced concentration in lending does not necessarily increase risk, because a well-functioning interbank market allows to achieve the necessary diversification. This greater need for risk sharing, though, increases the risk of cross-border contagion and the likelihood of widespread banking crises. However, even though integration increases the risk of contagion it improves welfare if it permits banks to realize specialization benefits.