Experts at King's College London found the immune response triggered by the skin condition could stop tumours forming by shedding potentially cancerous cells.
Genetically engineered mice lacking three skin proteins - known as "knock-out" mice - were used to replicate some of the skin defects found in eczema sufferers.
Researchers compared the effects of two cancer-causing chemicals with normal mice and found the number of benign tumours per mouse was six times lower in knock-out mice.
Both types of mice were equally susceptible to getting cancer-causing mutations, King's College said, but an exaggerated inflammatory reaction in knock-out mice led to enhanced shedding of potentially cancerous cells.
Previous studies have suggested eczema is linked with a reduced risk of skin cancer but it has been difficult to prove because symptoms vary and drugs used to treat the condition might also influence cancer.
The study, published in eLife, is the first to show that allergy caused by eczema could protect against skin cancer, King's College said.
Professor Fiona Watt, director of its centre for stem cells and regenerative medicine, said the results established "a clear link between cancer susceptibility and an allergic skin condition in our experimental model. They also support the view that modifying the body's immune system is an important strategy in treating cancer."