William David McElroy was born in Rogers, Texas. He obtained a B.A. from Stanford University in Palo Alto, California in 1939, an M.A. from Reed College in Portland, Oregon, in 1941, and a Ph.D. from Princeton University in 1943. After graduating, he remained at Princeton until 1945, working with his mentor E. Newton Harvey on a wartime research project for the U.S. Office of Scientific Research and Development. McElroy then returned to Stanford on a National Research Council Fellowship to work with George Beadle. In 1946, he joined the faculty of Johns Hopkins University and also became founding director of the McCollum-Pratt Institute. He was later appointed chairman of the Biology Department (1956) and remained at Johns Hopkins until 1969 when he moved to Washington, D.C., to become director of the National Science Foundation. In 1972, after finishing his term as director, McElroy was appointed chancellor of the University of California, San Diego. He remained at San Diego until his death in 1999.
While at Johns Hopkins, McElroy carried out an experiment that would influence the direction of his career. He showed that light emission in the extracts of the firefly lantern required ATP. This marked the beginning of McElroy's lifelong research on bioluminescence. Using the firefly system he later purified and crystallized luciferase and determined the structure of firefly luciferin. McElroy eventually cloned the firefly luciferase gene and expressed it in several organisms. He was a leader in discovering practical applications for firefly luciferase including using luciferase for the determination of ATP. Today, luciferase is widely used to test for the presence of organisms contaminating foods and as a reporter of gene expression in biology and medical research and diagnostics.
McElroy was very active on the editorial boards of many journals and was founding editor of Biochemical and Biophysical Research Communications. In addition to serving as president of the American Society of Biological Chemists in 1963, he was president of the American Institute of Biological Sciences and the American Association for the Advancement of Science. He served on the President's Science Advisory Committee under U.S. Presidents John F. Kennedy and Lyndon B. Johnson, was elected to the National Academy of Sciences in 1963, and was a member of the President's Committee on the National Medal of Science Award in 1972.