Natural D-serine (D-Ser) has been detected in animals more than two decades ago, but little is known about the physiological functions of D-Ser. Here we reveal sleep regulation by endogenous D-Ser. Sleep was decreased in mutants defective in D-Ser synthesis or its receptor the N-methyl-D-aspartic receptor 1 (NMDAR1), but increased in mutants defective in D-Ser degradation. D-Ser but not L-Ser rescued the phenotype of mutants lacking serine racemase (SR), the key enzyme for D-Ser synthesis. Pharmacological and triple gene knockout experiments indicate that D-Ser functions upstream of NMDAR1. Expression of SR was detected in both the nervous system and the intestines. Strikingly, reintroduction of SR into specific intestinal epithelial cells rescued the sleep phenotype of sr mutants. Our results have established a novel physiological function for endogenous D-Ser and a surprising role for intestinal cells.