Some vertebrate species have evolved means of extending their visual sensitivity beyond the range of human vision. One mechanism of enhancing sensitivity to long-wavelength light is to replace the 11-cis retinal chromophore in photopigments with 11-cis 3,4-didehydroretinal. Despite over a century of research on this topic, the enzymatic basis of this perceptual switch remains unknown. Here, we show that a cytochrome P450 family member, Cyp27c1, mediates this switch by converting vitamin A1 (the precursor of 11-cis retinal) into vitamin A2 (the precursor of 11-cis 3,4-didehydroretinal). Knockout of cyp27c1 in zebrafish abrogates production of vitamin A2, eliminating the animal's ability to red-shift its photoreceptor spectral sensitivity and reducing its ability to see and respond to near-infrared light. Thus, the expression of a single enzyme mediates dynamic spectral tuning of the entire visual system by controlling the balance of vitamin A1 and A2 in the eye.