We study empirically the reaction of fiscal policy to changes in the permanent and transitory components of GDP in a panel of countries. We find evidence that government spending tends to be counter-cyclical conditional on temporary shocks and pro-cyclical conditional on permanent shocks. We also find no evidence that developing countries are systematically different from developed ones in terms of fiscal policy. We present a theory featuring a fiscal reaction function to the output gap and a measure of debt sustainability. The fiscal impulse response to a permanent (temporary) shock to GDP is positive (negative) as the effect on debt sustainability (current output gap) dominates. The results are mostly sensitive to the relative weight of debt sustainability in the fiscal reaction function as well as to the extent of real rigidities in the economy.