It led to them finding one member of staff at Rosie Hospital, in Cambridge, who may have unwittingly carried and spread the infection.
They say it is the first time rapid genetic testing has been used to track and then stop an outbreak.
One expert said this would soon become "standard practice" in hospitals.
Doctors were concerned after MRSA was detected in 12 babies during routine screening.
However, current tests could not tell if it was one single outbreak being spread around the unit or if they were separate cases being brought into the hospital. About one in 100 people carry MRSA on their skin without any health problems.
To find out, researchers at the University of Cambridge and the Sanger Institute embarked on more sophisticated version of a paternity test.
They compared the entire genetic code of MRSA bugs from each baby to build a family tree. It showed they were all closely related and part of the same outbreak.
After two months without a case and deep cleaning the ward, another case appeared. Analysing the DNA showed that it was again part of the outbreak and attention turned to a carrier.