The study's lead author, professor Bob Hancox, said this exposure may alter immune function.
Parents of those in the Dunedin study reported their children's thumb-sucking and nail-biting habits at ages 5, 7, 9 and 11.
Participants were checked at 13 and 32 for atopic sensitisation - a positive skin-prick test to at least one common allergen.
At 13, the prevalence of sensitisation was lower among children who had sucked their thumbs or bitten their nails. Just over a third had a positive skin-prick test, compared with 49 per cent for the rest of the participants.
Children who had both bitten their nails and sucked their thumbs had an even lower risk of allergy at 31 per cent, Hancox said.
The associations were still present at age 32 and persisted even with adjustments for factors such as sex, parental history of allergies, pet ownership, breast-feeding and parental smoking, he said.
"The findings support the 'hygiene hypothesis', which suggests that being exposed to microbes as a child reduces your risk of developing allergies."
The researchers did not suggest encouraging the habits in children. It was unclear if there was a true health benefit, Hancox said.
Medical student Stephanie Lynch said they found no difference in risk for developing allergic diseases such as asthma or hay fever.