Although many animals use the Earth's magnetic field for orientation and navigation, the precise biophysical mechanisms underlying magnetic sensing have been elusive. One theoretical model proposes that geomagnetic fields are perceived by chemical reactions involving specialized photoreceptors. However, the specific photoreceptor involved in such magnetoreception has not been demonstrated conclusively in any animal. Here we show that the ultraviolet-A/blue-light photoreceptor cryptochrome (Cry) is necessary for light-dependent magnetosensitive responses in Drosophila melanogaster. In a binary-choice behavioural assay for magnetosensitivity, wild-type flies show significant naive and trained responses to a magnetic field under full-spectrum light ( approximately 300-700 nm) but do not respond to the field when wavelengths in the Cry-sensitive, ultraviolet-A/blue-light part of the spectrum (<420 nm) are blocked. Notably, Cry-deficient cry(0) and cry(b) flies do not show either naive or trained responses to a magnetic field under full-spectrum light. Moreover, Cry-dependent magnetosensitivity does not require a functioning circadian clock. Our work provides, to our knowledge, the first genetic evidence for a Cry-based magnetosensitive system in any animal.