Ischemic stroke is a leading cause of death and disability worldwide, and autophagy may be involved in the pathological process of cerebral ischemia/reperfusion injury. Hydrogen sulfide (H2S) is an endogenous gasotransmitter with protective effects against multiple diseases. Here, we tested the effect of H2S on cerebral ischemia/reperfusion injury in rats. Sodium hydrosulfide (NaHS), an H2S donor, improved neurological function and reduced the size of the infarcts induced by transient middle cerebral artery occlusion (MCAO) followed by reperfusion in rats. NaHS treatment reduced the lactate dehydrogenase (LDH) activity in the serum (a marker of cellular membrane integrity) and the expression of cleaved caspase‐3 (a marker for apoptosis) in the brains of MCAO rats. We also found that autophagy was overactivated in the brains of MCAO rats, as indicated by an increased ratio of LC3 II to I, decreased expression of p62, and transmission electron microscope detection. NaHS treatment significantly inhibited the autophagic activity in the brains of MCAO rats. Furthermore, PC12 cells were subjected to oxygen–glucose deprivation/reoxygenation (OGD/R) to mimic MCAO in vitro. We found that NaHS treatment reduced cellular injury and suppressed overactivated autophagy induced by OGD/R in PC12 cells. An autophagy stimulator (rapamycin) eliminated the protective effect of NaHS against LDH release and caspase‐3 activity induced by OGD/R in PC12 cells. An autophagy inhibitor (3‐methyladenine, 3‐MA) also reduced the cellular injury induced by OGD/R in PC12 cells. In conclusion, the results indicate that overactivated autophagy accelerates cellular injury after MCAO in rats and that exogenous H2S attenuates cerebral ischemia/reperfusion injury via suppressing overactivated autophagy in rats.