A dynamic stochastic model of a small open economy with a two-level banking intermediation structure, a risk-sensitive regulatory capital regime, and imperfect capital mobility is developed. Firms borrow from a domestic bank and the bank borrows on world capital markets, in both cases subject to a premium. A sudden flood in capital flows generates an expansion in credit and activity, as well as asset price pressures. Countercyclical capital regulation, in the form of a Basel III-type rule based on credit gaps, is effective at promoting macro stability (defined in terms of the volatility of a weighted average of inflation and output deviations) and financial stability (defined in terms of three measures based on asset prices, the credit-to-GDP ratio, and the ratio of bank foreign borrowing to GDP). However, because the gain in terms of reduced economic volatility exhibits diminishing returns, in practice a countercyclical regulatory capital rule may need to be supplemented by other, more targeted macroprudential instruments when shocks are large and persistent.