In most species daily rhythms are synchronized by the photoperiodic cycle. They are generated by the circadian system, which is made of a pacemaker, an entrainment pathway to this clock, and one or more output signals. In vertebrates, melatonin produced by the pineal organ is one of these outputs. The production of this time-keeping hormone is high at night and low during the day. Despite the fact that this is a well-preserved pattern, the pathways through which the photoperiodic information controls the rhythm have been profoundly modified from early vertebrates to mammals. The photoperiodic control is direct in fish and frogs and indirect in mammals. In the former, full circadian systems are found in photoreceptor cells of the pineal organ, retina, and possibly brain, thus forming a network where melatonin could be a hormonal synchronizer. In the latter, the three elements of a circadian system are scattered: the photoreceptive units are in the eyes, the clocks are in the suprachiasmatic nuclei of the hypothalamus, and the melatonin-producing units are in the pineal cells. Intermediate situations are observed in sauropsids. Differences are also seen at the level of the arylalkylamine N-acetyltransferase (AANAT), the enzyme responsible for the daily variations in melatonin production. In contrast to tetrapods, teleost fish AANATs are duplicated and display tissue-specific expression; also, pineal AANAT is special--it responds to temperature in a species-specific manner, which reflects the fish ecophysiological preferences. This review summarizes anatomical, structural, and molecular aspects of the evolution of the melatonin-producing system in vertebrates.