Melatonin, which is synthesized by the pineal gland and released into the blood, exhibits antitumor properties. However, the mechanisms underlying these effects, particularly in stomach cancer, remain unknown. In the present study, the effect of melatonin on the nuclear factor (NF)-κB signaling pathway and the mitogen-activated protein kinase signaling pathway, involving p38 and c-Jun-N-terminal kinase (JNK), were investigated in SGC7901 gastric cancer cells. In addition, the effect of melatonin on the survival, migration and apoptosis of these cells was investigated in vitro in order to evaluate the use of melatonin for the treatment of gastric cancer. The results of the present study revealed that melatonin decreased the viability and migration of SGC7901 cells. Furthermore, melatonin induced apoptosis. Melatonin was identified to elevate the expression levels of phosphorylated (p)-p38 and p-JNK protein, and decrease the expression level of nucleic p-p65. These results suggest that the protein levels of p65, p38 and JNK are associated with the survival of SGC7901 cells following treatment with melatonin. The optimal concentration of melatonin was demonstrated to be 2 mM, which significantly induced apoptosis following a 24 h treatment period. These findings suggest that conflicting growth signals in cells may inhibit the efficacy of melatonin in the treatment of gastric cancer. Therefore, adjunct therapy would be required to improve the efficacy of melatonin in the treatment of cancer.