Nightmares are intense and distressing dreams that occur during rapid eye movement (REM) sleep. They serve as a way for the brain to process emotions, memories, and experiences, helping individuals cope with fears and anxieties in a safe environment.