In addition to their use in relieving the symptoms of various diseases, ketogenic diets (KDs) have also been adopted by healthy individuals to prevent being overweight. Herein, we reported that prolonged KD exposure induced cardiac fibrosis. In rats, KD or frequent deep fasting decreased mitochondrial biogenesis, reduced cell respiration, and increased cardiomyocyte apoptosis and cardiac fibrosis. Mechanistically, increased levels of the ketone body β-hydroxybutyrate (β-OHB), an HDAC2 inhibitor, promoted histone acetylation of the Sirt7 promoter and activated Sirt7 transcription. This in turn inhibited the transcription of mitochondrial ribosome-encoding genes and mitochondrial biogenesis, leading to cardiomyocyte apoptosis and cardiac fibrosis. Exogenous β-OHB administration mimicked the effects of a KD in rats. Notably, increased β-OHB levels and SIRT7 expression, decreased mitochondrial biogenesis, and increased cardiac fibrosis were detected in human atrial fibrillation heart tissues. Our results highlighted the unknown detrimental effects of KDs and provided insights into strategies for preventing cardiac fibrosis in patients for whom KDs are medically necessary.