Barbaloin (Bar) has a myocardial protective effect, but its mechanism of action is uncertain. The endoplasmic reticulum stress (ERS)-mediated apoptosis pathway serves an important role in the pathogenesis of myocardial ischemia-reperfusion injury (MIRI). Inhibiting ERS may significantly improve the progression of MIRI and serve a role in its prevention. Therefore, based on current knowledge of ERS-mediated cardiomyocyte apoptosis and the cardioprotective effect of Bar, the purpose of the present study was to further evaluate the myocardial protective effect and potential mechanisms of Bar pretreatment in MIRI. The present study established a MIR rat model and randomly divided these rats into four groups. Prior to myocardial ischemia, Bar (20 mg/kg) was administered to rats once daily for 1 week. Myocardial blood serum lactate dehydrogenase and creatine kinase were subsequently measured. A terminal deoxynucleotidyl transferase mediated dUTP nick end labeling assay was used to evaluate the myocardial protective effect of Bar pretreatment on MIRI. To assess whether the ERS signaling pathway was involved in the myocardial protection mechanism of Bar pretreatment, the expression levels of ERS-associated proteins, protein canopy homolog 2 (CNPY2), glucose regulatory protein 78, transcriptional activator 4, C/EBP-homologous protein (CHOP), PKR endoplasmic reticulum kinase (PERK), caspase-12 and caspase-3 were detected by western blot analysis, immunohistochemistry or reverse transcription-quantitative polymerase chain reaction. The results confirmed that Bar pretreatment significantly reduced the damage and the level of apoptosis caused by MIR. Bar pretreatment significantly inhibited the expression of ERS-associated proteins in cardiomyocytes. In addition, the immunohistochemistry results demonstrated that Bar pretreatment significantly inhibited the CNPY2-positive cell apoptosis ratio of cardiomyocytes. Therefore, the results of the current study suggested that CNPY2 is present in cardiomyocytes and participates in the development of MIRI by initiating the PERK-CHOP signaling pathway. Bar pretreatment may attenuate MIRI by inhibiting the CNPY2-PERK apoptotic pathway.