When William C. Dement began working as a medical researcher in the 1950s, the topic of sleep was considered a yawn, scientifically speaking — an area perhaps appropriate for Freudian psychoanalysis but not for vigorous investigation by white-coated lab experts.

But with a pair of colleagues at the University of Chicago, Dr. Dement conducted some of the earliest studies of rapid eye movement sleep, known as REM, which he identified as the stage in which most dreams happen. He also revealed the phases of the sleep cycle, using electroencephalograms to monitor subjects’ brain waves and polysomnography to track eye movements, blood oxygen levels and other body functions during sleep.

Dr. Dement demonstrated that slumber was far from a single, passive state. And over the next few decades he helped turn the study of sleep into a robust scientific discipline, presiding over experiments on himself, his family, a few Rockettes dancers, a colony of narcoleptic dogs and a teenager named Randy Gardner, who in 1964 claimed to have become the world’s champion insomniac by going 11 days without sleep.

His research and advocacy helped awaken the medical establishment to the dangers of sleep deprivation, which Dr. Dement and his colleagues linked to fatal car crashes and ailments such as diabetes. He also spotlighted the cardiovascular risks of disorders such as sleep apnea, in which a sleeper’s breathing is repeatedly interrupted.

“He was the father of sleep medicine. Everything started with Bill,” said his Stanford University colleague Emmanuel Mig­not, an authority on narcolepsy. For years, he added in a phone interview, Dr. Dement “was a voice in the wilderness, trying to draw attention to sleep issues at a time when it wasn’t taken too seriously.”

Dr. Dement was 91 when he died June 17 at a hospital in Stanford, Calif. The cause was complications from a heart procedure, said his son, Nick Dement.

A passionate and even whimsical teacher and mentor, Dr. Dement was known for practicing what he preached, granting extra credit to students who nodded off in his undergraduate sleep class — then waking them up with a squirt gun and urging them to stand on their feet and declare, “Drowsiness is red alert!”

The mantra served as a reminder that drowsiness could be deadly, especially on the road, and became a kind of motto for Dr. Dement. A onetime professional bassist, he was said to have turned from jazz to medicine after deciding that it was better to be a mediocre doctor than a mediocre musician. He went on to champion the creation of a jazz program at Stanford while notching a series of firsts in the field of sleep science.

Dr. Dement wrote one of the first university textbooks on sleep; founded the Stanford Sleep Disorders Clinic, considered the first of hundreds of sleep labs across the country; and created the first major professional organization for sleep researchers, now known as the American Academy of Sleep Medicine.

He was also a founding editor of Sleep, a prominent academic journal, and created one of the first undergraduate courses on sleep, “Sleep and Dreams,” teaching an estimated 20,000 students in the decades since its inception in 1971. Some 600 undergrads packed into Stanford Memorial Chapel that year, and Dr. Dement lectured from the pulpit before deciding that doing so “seemed a bit blasphemous.”

“His joy of teaching, learning, and doing research was infectious,” said Mary A. Carskadon, a psychiatry and human-behavior professor at Brown University. She had previously worked with Dr. Dement at what is now the Stanford Sleep Medicine Center, leading a decade-long study that suggested that insufficient sleep could carry over from night to night in the form of “sleep debt.”

While treating sleep as a public health issue, Dr. Dement became a leading proponent of the importance of getting a good night’s sleep — generally six to eight hours, he said, with the length varying from person to person. “He really became an evangelist against drowsy driving,” said Rafael Pelayo, another longtime colleague. “Any time you hear someone talking about sleep and workplace safety, it’s all inspired by Bill Dement’s work.”

He was also a scholar of narcolepsy and sleep apnea, at a time when few scientists focused on sleep disorders. In the 1980s, he promoted research suggesting that as much as 20 percent of the population was suffering from sleep apnea. “People were really thinking he was crazy,” Mignot said, adding that later studies vindicated his views. The disorder has been linked to high blood pressure, among other conditions.

Dr. Dement appeared on “The Tonight Show Starring Johnny Carson” and testified on sleep before Congress, helping to galvanize the creation of the National Commission on Sleep Disorders Research in 1988. With Dr. Dement as chairman, the commission issued a report finding that 40 million Americans suffered from chronic sleep disorders, with up to 30 million more experiencing intermittent sleep problems. Bleary-eyed employees, the commission estimated, resulted in $150 billion of reduced workplace productivity.

After the report was released in 1993, Congress created the National Center on Sleep Disorders Research, which coordinates research as part of the National Institutes of Health. Its creation “was huge” for the field, said Carskadon, who credited Dr. Dement with “almost single-handedly” spurring its formation. “He fundraised, he lobbied Congress, he was out there on the stump and he galvanized others in our community. Without him,” she added with a sigh, “there’s just no way.”

William Charles Dement was born in Wenatchee, Wash., on July 29, 1928, and grew up in Walla Walla, where his father’s family owned a flour mill. By the close of World War II he was serving in Japan with the Army, editing a regiment newspaper and developing a clear, concise writing style that later drew praise from academics.

In 1951 he received a bachelor’s degree from the University of Washington in Seattle, where he hosted jam sessions from his house boat on Lake Union, playing with musicians such as Quincy Jones and Stan Getz.

Dr. Dement was training to become a psychiatrist when he became interested in sleep while at the University of Chicago, where physiologist Nathaniel Kleitman and graduate student Eugene Aserinsky were credited with discovering REM sleep in 1953. Building on their work, Dr. Dement later established the link between REM sleep and dreaming.

“Aserinsky told me about what he had been seeing in the sleep lab and then threw in the kicker that really hooked me: ‘Dr. Kleitman and I think these eye movements might be related to dreaming,’ ” he recalled in a 1999 book, “The Promise of Sleep.” “For a student interested in psychiatry, this offhand comment was more stunning than if he had just offered me a winning lottery ticket. It was as if he told me, ‘We found this old map to something called the Fountain of Youth.’ ”

Dr. Dement received his medical degree in 1955 and his PhD in neurophysiology in 1957, both at Chicago. While doing his medical internship at Mount Sinai Hospital in Manhattan, he set up a sleep lab out of his apartment, working with members of the Rockettes who apparently responded to an advertisement for a study. “He actually got the NIH to pay for half of his rent, because half of his apartment was to be used for sleep research,” Pelayo said.

After joining Stanford’s psychiatry department in 1963, Dr. Dement launched the sleep clinic with colleagues including Christian Guilleminault, who died last July. He was later praised for promoting the work of colleagues and students such as Mark Rosekind, a former administrator of the National Highway Traffic Safety Administration, and Charles A. Czeisler, now a leading sleep authority at Harvard.

In an email, his former student Clete A. Kushida, medical director of the Stanford Sleep Medicine Center, wrote that Dr. Dement “mentored generations of sleep clinicians and researchers,” adding that “his high standards for academic excellence, combined with his fun-loving nature and sharp wit, has inspired many to follow his trailblazing footsteps.”

His wife of 58 years, the former Eleanor “Pat” Weber, was “the glue” that kept the Stanford sleep community together, said Dr. Dement’s son, Nick. “Almost everybody used my mom as social director and therapist at times,” he said, recalling dinner parties that began with Pat holding forth over a pan of paella. She died in 2014.

In addition to Nick, a physician in Phoenix, survivors include two daughters, Elizabeth Dement and Catherine Roos, both of Stanford, Calif. His six grandchildren include Nick’s son Zaniel Zaiden Zooey Dement, whose initials — ZZZ — were selected in honor of Dr. Dement.

Dr. Dement formally retired in 2003 but kept teaching his “Sleep and Dreams” course until about five years ago, when Pelayo succeeded him at the head of the class. Even then, he continued participating in the course, arriving in a golf cart dubbed the Sleep & Dreams Shuttle and occasionally chiming in with help from a wireless microphone.

He otherwise received the same treatment as students.

“If he fell asleep and I noticed,” Pelayo said with a laugh, “I would always squirt him with water.”