A team of scientists halted an outbreak of MRSA in a special care baby unit by cracking the superbug’s genetic code.
It meant researchers were quickly able to identify the bacterial strain causing the outbreak and trace it back to one health worker.
The worker was treated to remove the MRSA colonisation, which stopped the spread of the superbug in its tracks.
The scientists are now developing the concept into a simple system that can be used routinely by hospital staff who are not genetics experts. They are aiming to have it ready in a "few years".
Professor Sharon Peacock, from Cambridge University, who led the research team, said : "What we're working towards is effectively a 'black box'. Information on the genome sequence goes into the system and is interpreted, and what comes out the other end is a report to the health care worker."
She said the 'black box' would be able to give information about how the strain would react to antibiotics and about how quickly it could spread.
Testing would cost just a few pounds and the results would be available in hours.
The research was carried out at the special care baby unit at the Rosie Hospital in Cambridge, part of Cambridge University Hospitals NHS Foundation Trust.
The scientists used a technique called rapid whole genome sequencing, which maps an organism's entire genetic code, to analyse MRSA bacteria taken from 12 babies.
The team was quickly able to confirm that 10 babies were part of an MRSA outbreak involving a previously unknown strain of the bug.
DNA sequencing showed it was caused by a strain carried to the ward by one of 154 health workers, who had been screened for MRSA.
"The staff member was decolonised and went back to work, and we believe this brought the outbreak to a close," said Dr Julian Parkhill, head of pathogen genomics at the Wellcome Trust Sanger Institute in Hinxton, Cambridgeshire, who worked on the research.
One in 100 people carry MRSA (methicillin resistant Staphylococcus aureus) without any health problems. However, can kill if it gets into wounds. It is spread by skin contact.
It is believed to be the first time DNA sequencing has been used to contain an infectious disease outbreak at a hospital.
A Health Protection Agency report in May said more than six per cent of hospital patients in England acquired some form of infection during their stay.
However, a survey found MRSA hospital infection rates had fallen significantly in recent years.