William G. Speed III, 87, whose lifelong study of headaches was prompted by a migraine he suffered while an undergraduate student, died of congestive heart failure Nov. 15 at Greater Baltimore Medical Center.

Dr. Speed became interested in the field while at Trinity College in Hartford, Conn., when he awoke one morning in severe pain and was told he was suffering a migraine. In an autobiographical sketch, he recalled being annoyed by a doctor who seemed to know little about headaches.

"He treated the whole situation rather cavalierly," Dr. Speed wrote. " 'Hey, you had a headache -- so what!' "

Born in Baltimore, Dr. Speed knew from the time he was 8 that he wanted to become a doctor. While he was working toward his medical degree at the Johns Hopkins University School of Medicine, senior physicians there knew he had studied medical literature about headaches and sought his advice. When he went into practice in 1947, those physicians began to refer patients to him.

When he began practicing, headaches were commonly attributed to stress, tension, nerves or anxiety. Dr. Speed, however, said those reasons didn't seem to apply to many of his patients. His belief that there was an organic explanation for headaches was later proved to be correct.

He was a founding member of what is now the American Headache Society and was its president from 1986 to 1988. In 1989, the group presented him with its Distinguished Clinician Award.

"Bill Speed pioneered the differential diagnosis of chronic headache, an extremely complicated field that few were willing to take on," said Richard Starr Ross, a cardiologist and former dean of the Hopkins School of Medicine. "He was a world-renowned leader, if not the originator, of this entire medical subspecialty. Patients came to him from all over the globe for his advice and treatment."

Dr. Speed was an associate professor of medicine at Hopkins and for 54 years was on the staff of Johns Hopkins Hospital. He retired in 2002.

His first wife, Jean LaVine Speed, to whom he was married for 51 years, died in 1998. Margaret Turner Speed, his wife of five years, died in July.

Survivors include three children; seven stepchildren; a brother; and four grandchildren.