Ischemia/reperfusion (I/R) injury following myocardial infarction is a major cause of cardiomyocyte death and impaired cardiac function. Although clinical data show that metformin is effective in repairing cardiac I/R injury, its efficacy is hindered by non-specific targeting during administration, a short half-life, frequent dosing, and potential adverse effects on the liver and kidneys. In recent years, injectable hydrogels have shown substantial potential in overcoming drug delivery challenges and treating myocardial infarction. To this end, we developed a natural polymer hydrogel system comprising methacryloylated chitosan and methacryloylated gelatin modified with polyaniline conductive derivatives. In vitro studies demonstrated that the optimized hydrogel exhibited excellent injectability, biocompatibility, biodegradability, suitable mechanical properties, and electrical conductivity. Incorporating metformin into this hydrogel significantly extended the administration cycle, mitigated mitochondrial damage, decreased abnormal ROS production, and enhanced cardiomyocyte function. Animal experiments indicated that the metformin/hydrogel system reduced arrhythmia incidence, infarct size, and improved cardiac mitochondrial and overall cardiac function, promoting myocardial repair in I/R injury. Overall, the metformin-loaded conductive hydrogel system effectively mitigates mitochondrial oxidative damage and improves cardiomyocyte function, thereby offering a theoretical foundation for the potential application of metformin in cardioprotection.