Both aspirin and ibuprofen are Non-Steroidal Anti-Inflammatory Drugs (NSAIDs), and it is their ability to interfere with inflammation in the human body which appears to be the key.
Two body chemicals which help produce inflammation, COX1 and 2, are thought to play roles in the development of cancer by influencing how cells divide and die, the production of new blood vessels that can "feed" tumours, and influence the body's immune responses.
It appears NSAIDS inhibit these chemicals.
Women taking either aspirin or ibuprofen regularly had a 12% lower chance of developing breast cancer compared to those who did not use them at all, while regular ibuprofen use appeared to have the biggest effect.
The research, which looked at information from 2.7 million women, was published in the Journal of the National Cancer Institute.
However, experts warned long-term use of painkillers can have serious side-effects.
Dr Mahyar Etminan, from the University of British Columbia, who led the research, said the results were "encouraging", and could help scientists trying to understand the complex origins of breast cancer.
However, he warned against women adopting painkillers as part of a cancer prevention lifestyle.
"We don't recommend the routine use of NSAIDs for breast cancer prevention until large randomised trials confirm these findings." He said results from a trial of this type would be available next year.
The regular use of painkillers is problematic because, in some people, they can cause serious side-effects, including stomach ulcers, increased risk of stroke, asthma and heart, liver and kidney problems.
The potential benefits of reducing breast cancer risk would have to be balanced against these.
This advice was echoed by Breakthrough Breast Cancer, which urged women worried about breast cancer risk to talk to their GP rather than simply take painkillers.
Head of policy Sarah Rawlings said: "The potential of anti-inflammatory drugs, such as aspirin, to lower the chances of developing breast cancer is very interesting, but as the researchers say, large scale trials are needed to confirm these findings.
"Anti-inflammatory drugs can have potentially very serious side-effects when taken over a long period."