Humans have long been fascinated by chameleons changing colour to dazzle mates, scare rivals and confuse predators.
On Tuesday, scientists said they uncovered the mechanism of the feat, and that the results of their investigation astounded them.
Rather than use pigments to switch colour, nanocrystals in the lizards' skin are tuned to alter the reflection of light, they found.
"We were surprised," Michel Milinkovitch, a biologist at the University of Geneva told AFP.
"It was thought they were changing colour through... pigments. The real mechanism is totally different and involves a physical process," he added.
Colour-switching in chameleons is the preserve of males.
They use it to make themselves more flamboyant to attract mates and frighten off challengers, or duller to evade predators.
The mature panther chameleon used in the study, for example, can change the background colour of its skin from green to yellow or orange, while blue patches turn whitish and then back again.
In most other colour-changing animals, the pigment melanin alters a colour's brightness by dispersing or concentrating within cells called melanophores, thus changing colour intensity but not hue.
This process had long been thought to explain chameleons' colour change as well, the team said. But that theory turned out to be false.
Skin analysis revealed that the change is regulated by transparent nano-objects called photonic crystals found in a layer of cells dubbed iridophores, which lie just below the chameleon's pigment cells.
Iridophores are also found in other reptiles and amphibians like frogs, giving them the green and blue colours rarely found in other vertebrates.
In chameleons, however, nanocrystal lattices within the iridophores can be "tuned" to change the way light is reflected, the university said in a statement.
- Blue for calm -
"When the chameleon is calm, the latter (crystals) are organised into a dense network and reflect the blue wavelengths" of incoming light, it said.
"In contrast, when excited, it loosens its lattice of nanocrystals, which allows the reflection of other colours such as yellows or reds."
The team used biopsies of chameleon skin, pre- and post-excitement, combined with optical microscopy and high-resolution videography to study the phenomenon.
They also discovered that chameleons have a second, deeper layer of iridophore cells.
These contain "larger and less ordered" crystals that reflect infrared wavelengths from strong sunlight -- in essence, a clever heat shield.
"The organisation of iridophores in two superimposed layers constitute an evolutionary novelty," the team said.
"It allows the chameleons to rapidly shift between efficient camouflage and spectacular display, while providing passive thermal protection."
Other reptiles have only one type of iridophore cell which cannot be used to change colour, the researchers said.
Next, scientists would like to figure out the mechanisms that allow chameleons to tune the crystal lattice.
The groundbreaking findings were published in the independent journal Nature Communications.
Discoveries in the animal world have spawned a field called "biomimicry".
Engineers often seek to replicate wonders of evolution such as spider's silk and gecko feet for products with commercial or military use.
A video of the panther chameleon's transformation can be seen below: