Emerging market economies often face sudden stops in capital inflows or reduced access to the international capital market, a development that can cause serious disruptions in economic activity. This paper analyzes what monetary policy can accomplish in such an event. Optimal monetary policy exploits export revenues to minimize the impact on the domestic economy. However, this approach will not completely insulate the economy from some contraction. Domestic currency depreciation combined with high interest rates is needed to achieve this result. The paper shows that the arrival of the sudden stop further aggravates the time inconsistency problem. Optimal policy is fairly well approximated by a flexible targeting rule, which stabilizes a basket composed of domestic price inflation, exchange rate, and output. For some parameterizations, the best rule can be specified as an interest rate rule that responds to the natural interest rate, inflation, output, and exchange rate depreciation. We further show that from a welfare perspective, the desirability of a fixed exchange rate regime depends on the economic environment.