Pregnancy imposes a substantial metabolic burden on women through weight gain and insulin resistance. Lactation reduces the risk of maternal postpartum diabetes, but the mechanisms underlying this benefit are unknown. Here, we identified long-term beneficial effects of lactation on beta cell function, which last for years after the cessation of lactation. We analyzed metabolic phenotypes including beta cell characteristics in lactating and non-lactating humans and mice. Lactating and non-lactating women showed comparable glucose tolerance at 2 months after delivery, but after a mean of 3.6 years, glucose tolerance in lactated women had improved compared to non-lactated women. In humans, the disposition index, a measure of insulin secretory function of beta cells considering the degree of insulin sensitivity, was higher in lactated women at 3.6 years after delivery. In mice, lactation improved glucose tolerance and increased beta cell mass at 3 weeks after delivery. Amelioration of glucose tolerance and insulin secretion were maintained up to 4 months after delivery in lactated mice. During lactation, prolactin induced serotonin production in beta cells. Secreted serotonin stimulated beta cell proliferation through serotonin receptor 2B in an autocrine and paracrine manner. In addition, intracellular serotonin acted as an antioxidant to mitigate oxidative stress and improved beta cell survival. Together, our results suggest that serotonin mediates the long-term beneficial effects of lactation on female metabolic health by increasing beta cell proliferation and reducing oxidative stress in beta cells.