As a Yale undergraduate majoring in astronomy and physics, Michele Dufault was used to extreme physical environments. She worked on underwater robotic vehicles last summer as a fellow at the Woods Hole Oceanographic Institution in Massachusetts. She also traveled to Houston as part of a team of undergraduates chosen by NASA to perform a plasma physics experiment in reduced gravity.

But it was a rudimentary machine — a lathe in a campus laboratory — that erased what everyone imagined to be a brilliant future for Ms. Dufault, who also found time to mentor girls interested in science and to play saxophone in Yale’s precision marching band.

On Tuesday, just weeks from graduating, she toiled late at night inside a machine shop in a chemistry lab, as she had for weeks while working on her senior thesis: investigating the possible use of liquid helium for detecting dark matter particles. Ms. Dufault, 22, was killed when her hair became caught in the lathe, whose rotating axis is used to hold materials like wood or metal being shaped.

Students and staff members were overwhelmed by the news on Wednesday, and met in small groups to share their grief. Linda Koch Lorimer, a Yale vice president and its secretary, called the death a “terrible accident” in a letter to students, and said counselors were available. A candlelight vigil was held Wednesday night in the courtyard of Saybrook College, the residential complex where Ms. Dufault lived on the New Haven campus.