A model of the domestic financial intermediation of foreign capital inflows based on agency costs is developed for studying financial crises in emerging markets. In equilibrium, the banking system becomes progressively more fragile under imperfect prudential regulation and public sector loan guarantees until a crisis occurs with a sudden reversal of capital flows. The crisis evolves endogenously as the banking system becomes increasingly vulnerable through the renegotiation of loans after idiosyncratic firm-specific revenue shocks. The model generates dynamic relationships between foreign capital inflows, domestic investment, corporate debt and equity values in an endogenous growth model. The model's assumptions and implications for the behavior of the economy before and after crisis are compared to the experience of five East Asian economies. The case studies compare three that suffered a crisis or near-crisis, Thailand and Malaysia, to two that did not, Taiwan Province of China and Singapore, and lend support to the model.