The stress-responsive epigenetic repressor histone deacetylase 4 (HDAC4) regulates cardiac gene expression. Here we show that the levels of an N-terminal proteolytically derived fragment of HDAC4, termed HDAC4-NT, are lower in failing mouse hearts than in healthy control hearts. Virus-mediated transfer of the portion of the Hdac4 gene encoding HDAC4-NT into the mouse myocardium protected the heart from remodeling and failure; this was associated with decreased expression of Nr4a1, which encodes a nuclear orphan receptor, and decreased NR4A1-dependent activation of the hexosamine biosynthetic pathway (HBP). Conversely, exercise enhanced HDAC4-NT levels, and mice with a cardiomyocyte-specific deletion of Hdac4 show reduced exercise capacity, which was characterized by cardiac fatigue and increased expression of Nr4a1. Mechanistically, we found that NR4A1 negatively regulated contractile function in a manner that depended on the HBP and the calcium sensor STIM1. Our work describes a new regulatory axis in which epigenetic regulation of a metabolic pathway affects calcium handling. Activation of this axis during intermittent physiological stress promotes cardiac function, whereas its impairment in sustained pathological cardiac stress leads to heart failure.