Moth antennae contain gyroscope-like sensors to help them control their course through the air, scientists say.
Up until now, the insects' wobble-free flight remained a mystery - especially because their love of low light meant they could not rely on visual cues.
But a US team found a structure at the base of the antennae that senses when the body starts to pitch or roll and relays this information to the brain.
The study, carried out on hawk moths, is published in the journal Science.
"Whenever a creature is moving about, it has to have sensory information to tell it what it has done," said Dr Sanjay Sane, a biologist at the University of Washington, Seattle, and the lead author of the Science paper.
"If a person unintentionally turns around, the inner ear system or eyes will provide that information and allow for a course correction.
"Flying creatures need to know that information too, and when the light is low, and the visual cues are hard to see, they have to depend more on the mechanosensory system."
The researchers uncovered the secrets of hawk moth (Manduca sexta) flight control by looking at what happened when the insects' antennae were removed.
Monitoring the antennae-less moths in a dimly lit flying chamber, the team discovered the moths' flight was extremely unsteady: they collided with the walls, flew backwards or crashed to the floor.
However, when the antennae were glued back on, the moths regained their agile grace.
The researchers found that a structure called Johnston's organ, which is found at the base of the moths' antennae, was the key.
Using vibrations from the antennae, which remain in fixed positions during flight, the organ can detect when and where the moth's body moves in relation to its antennae.
In essence, it is behaving much like a gyroscope on a ship or plane that gives the vehicle a frame of reference to move within.
Further investigation revealed the Johnston's organ then sends this information to the brain so the moth can shift its body back to the correct position.
The researchers said their findings are likely to apply to other flying insects with similar anatomies, such as butterflies or owl flies.
The study could also help with the design of robotic insects.
Dr Sane said: "There is a huge push to create tiny robotic flying insects. You could perhaps apply some of the principles we have found here."
Previous studies have found two-winged insects, such as house flies or mosquitoes, also use gyroscope-like sensors to control their flight. The "halteres" are attached to their hindwings.