Scientists have shed light on how a major cause of human and animal disease can jump between species, by studying its genes.
The findings reveal fresh insights into how new disease-causing strains of the bacteria - called Staphylococcus aureus - emerge.
Experts say the research could help improve the use of antibiotics and design better strategies for limiting the spread of disease.
S. aureus bacteria usually live harmlessly in our noses. If the bacteria get into a cut, however, they can cause infections that, in rare instances, can be deadly.
Antibiotic resistant strains of the bacteria, such as MRSA, are a major cause of hospital acquired infections.
The bacteria is also a major burden for the agricultural industry as it causes diseases such as mastitis in cows and skeletal infections in broiler chickens.
A team led by the University of Edinburgh's Roslin Institute analysed the entire genetic make-up of more than 800 strains of S. aureus that were isolated from people and animals.
The researchers sought to investigate the evolutionary history of the bacteria and key events that had allowed it to jump between species.
They found that humans were the likely original host for the bacteria. The first strains capable of infecting livestock emerged around the time animals were first domesticated for farming.
Cows have been a source of strains that now cause infections in human populations worldwide, the study found. The researchers say this highlights the importance of disease surveillance in people and animals in order to spot strains that could cause major epidemics.
The analysis revealed that each time the bacteria jumps species, it acquires new genes that enable it to survive in its new host. In some cases, these genes can also confer resistance to commonly used antibiotics.
Genes linked to antibiotic resistance are unevenly distributed among strains that infect humans compared with those that infect animals, the study found. The researchers say this reflects the distinct practices linked to antibiotic usage in medicine and agriculture.
Investigating how the bacteria are affected by genetic changes that occur after it jumps species could reveal opportunities to develop new anti-bacterial therapies, the researchers say.
It could also help to inform better strategies for managing infections to reduce the risk of transmission to people, and slow the emergence of antibiotic resistance.
The study, published in Nature Ecology & Evolution, involved researchers from the Universities of Edinburgh and Cambridge and the Wellcome Sanger Institute.
The Roslin Institute receives strategic funding from the Biotechnology and Biological Sciences Research Council.
Professor Ross Fitzgerald, Group Leader at the University of Edinburgh's Roslin Institute and Director of Edinburgh Infectious Disease, said: "This study has been a real collaborative effort between numerous research groups in the UK and beyond. Our findings provide a framework to understand how some bacteria can cause disease in both humans and animals and could ultimately reveal novel therapeutic targets."