The genetic basis of phenotypic changes in extreme environments is a key but rather unexplored topic in animal evolution. Here we provide an exemplar case of evolution by relaxed selection in the Somalian cavefish Phreatichthys andruzzii that has evolved in the complete absence of light for at least 2.8 million years. This has resulted in extreme degenerative phenotypes, including complete eye loss and partial degeneration of the circadian clock. We have investigated the molecular evolution of the nonvisual photoreceptor melanopsin opn4m2, whose mutation contributes to the inability of peripheral clocks to respond to light. Our intra-and inter-species analyses suggest that the 'blind' clock in P. andruzzii evolved because of the loss of selective constraints on a trait that was no longer adaptive. Based on this change in selective regime, we estimate that the functional constraint on cavefish opn4m2 was relaxed at ∼ 5.3 Myr. This implies a long subterranean history, about half in complete isolation from the surface. The visual photoreceptor rhodopsin, expressed in the brain and implicated in photophobic behavior, shows similar evolutionary patterns, suggesting that extreme isolation in darkness led to a general weakening of evolutionary constraints on light-responsive mechanisms. Conversely, the same genes are still conserved in Garra barreimiae, a cavefish from Oman, that independently and more recently colonized subterranean waters and evolved troglomorphic traits. Our results contribute substantially to the open debate on the genetic bases of regressive evolution.