Diabetes mellitus (DM) facilitates atrial fibrosis and increases the risk of atrial fibrillation (AF). The underlying mechanism of DM in causing AF remains mostly unknown and potential therapeutic targets for DM-induced AF are rarely reported. Hydrogen sulfide (H
2
S) has drawn considerable attention in recent years for its potential as a cardiovascular protector. Thus, the aim of the present study was to investigate the effect of H
2
S on DM-induced AF and the mechanism of action. Sprague-Dawley rats were divided into four groups, including the control group, the DM group, the H
2
S group and the DM+H
2
S group. The DM group and the DM+H
2
S group were administered streptozotocin to induce DM, whereas the other two groups were given citrate buffer as a control. The H
2
S group and the DM+H
2
S group were administered with an intraperitoneal injection of sodium hydrosulfide (precursor of H
2
S). AF inducibility, AF duration, atrial fibrosis and vital protein expression of oxidative stress were compared among the four groups. The DM group showed significantly higher AF incidence rates and duration (P<0.05). Histology results demonstrated severe atrial fibrosis in the DM group, and the PI3K/Akt/endothelial nitric oxide synthase (eNOS) pathway was significantly downregulated (P<0.05). However, when H
2
S was administered, the rats showed lower AF incidence and duration compared with the DM group. Additionally, H
2
S was able to mitigate the atrial fibrosis induced by DM, as well as the proliferation and migration of cardiac fibroblasts, as demonstrated by an MTT assay and real-time cell analyzer migration experiment. Western blotting showed that the expression levels of the PI3K/Akt/eNOS pathway in the DM+H
2
S group were significantly upregulated compared with those of the DM group (P<0.05). In summary, DM status can lead to the structural remodeling of atrial fibrosis, facilitating AF incidence and persistence. Administration of H
2
S does not affect the glucose level, but can significantly mitigate atrial fibrosis and reduce the incidence of AF induced by DM, probably via activation of the PI3K/Akt/eNOS pathway.