Melatonin is a hormone that your brain produces in response to darkness. It helps with the timing of your circadian rhythms (24-hour internal clock) and with sleep. Being exposed to light at night can block melatonin production.
Research suggests that melatonin plays other important roles in the body beyond sleep. However, these effects are not fully understood.