The scientists discovered that people with the rival bug Staphylococcus lugdunensis in their nostrils were less likely to have S. aureus.
The German team used various strains of genetically-modified S. lugdunensis to work out the crucial piece of genetic code that allowed it to win the fight to live among your nose hairs.
They eventually pinpointed a single crucial gene that contained the instructions for building a new antibiotic, which they named lugdunin.
Tests on mice showed lugdunin could treat superbug infections on the skin including MRSA, as well as Enterococcus infections.
One of the researchers, Dr Bernhard Krismer, said: "Some of the animals were completely clear, no single cell of the bacterium was detectable.
"Others were reduced, but still contained some bacteria and we also saw that the compound penetrated the tissue and acted on the deeper layer of the skin."
It will take years of testing before lugdunin could reach patients and it may not prove to be successful.
But new antibiotics are desperately needed as doctors face the growing challenge of infections that resist current drugs and could become untreatable.
'Pressure to eliminate'
Fellow researcher Prof Andreas Peschel said the body could be mined for new antibiotics.
"Lugdunin may be the first example of such an antibiotic, we have started a screening programme," he said.
And he even believes that people could one day be infected with genetically-modified bacteria to fight their infections.
He argued: "By introducing the lugdunin genes into a completely innocuous bacterial species we hope to develop a new preventive concept of antibiotics that can eradicate pathogens."
Prof Kim Lewis and Dr Philip Strandwitz, from the antimicrobial discovery centre at Northeastern University in the US, commented: "It may seem surprising that a member of the human microbiota - the community of bacteria that inhabits the body - produces an antibiotic.
"However, the microbiota is composed of more than a thousand species, many of which compete for space and nutrients, and the selective pressure to eliminate bacterial neighbours is high.