Metformin, a widely prescribed antidiabetic drug, has previously been shown to lower the risk of certain types of cancer, including that of breast cancer, and to improve prognosis. Its anticancer effects, which are mediated by the activation of AMP-activated protein kinase (AMPK), have become notable. The Sonic hedgehog (Shh) signaling pathway is involved in changes in mammary ducts and malignant transformation. The aim of the present study was to elucidate the role of the Shh pathway in mediating the anticancer effects of metformin and the correlation between AMPK and the Shh pathway. We investigated the effectiveness of metformin in inhibiting the proliferation, migration, invasion and stemness of breast cancer cells in vitro using RNA extraction and reverse transcription‑polymerase chain reaction (RT-PCR), western blot analysis, cell proliferation assay, scratch-wound assay (cell migration assay), cell invasion assay, mammosphere culture and flow cytometry. In in vivo experiments, a tumor xenograft model was used to detect the effects of metformin on cancer cell proliferation. The results revealed that the treatment of breast cancer cells with metformin led to the inhibition of the Shh signaling pathway. Importantly, metformin inhibited recombinant human Shh (rhShh)‑induced cell migration, invasion, and stemness, and impaired cell proliferation both in vitro and in vivo. Furthermore, the small interfering RNA (siRNA)‑mediated downregulation of AMPK reversed the inhibitory effects of metformin on rhShh‑induced Gli-1 expression and stemness. Our findings identified a role of the Shh signaling pathway in the anticancer effects of metformin in breast cancer. Furthermore, we revealed that the metformin-mediated inhibition of the Shh signaling pathway may be dependent on AMPK.