Pacemakers are implanted into the chest to regulate the heartbeat
A new pacemaker has been built inside a heart by converting beating muscle into cells which can organise the organ's rhythm, US researchers report.
The heartbeat is controlled by electrical signals and if these go awry the consequences can be fatal.
Scientists injected a genetically-modified virus into guinea pigs to turn part of their heart into a new, working pacemaker.
The study was published in the journal Nature Biotechnology.
A human heart is made up of billions of cells, but researchers say fewer than 10,000 are responsible for controlling the heartbeat.
Age and disease can lead to problems such as the heart pumping too fast or too slow - and it can even stop completely, in what is known as a cardiac arrest.
The solution is an implanted battery-powered pacemaker which will jolt the heart to keep it in line.
Instead a team of researchers at the Cedars-Sinai Heart Institute tried to restore the heart's own ability to dictate the beat by creating new pacemaker cells.
They used a virus to infect heart muscle cells with a gene, called Tbx18, which is normally active when pacemaker cells are formed during normal development in an embryo.
When heart cells were infected with the virus they became smaller, thin and tapered as they acquired the "distinctive features of pacemaker cells", the report said.
When the virus was injected into a region of the hearts of seven guinea pigs, five later had heartbeats which originated from their new pacemaker.
One of the researchers Dr Hee Cheol Cho, from Cedars-Sinai, told the BBC he expected the same method to work in the human heart as they used a human gene, Tbx18, to generate the effect.
However, far more animal testing would be needed before the technique would ever be considered in people.
Dr Cho added: "Electronic devices are limited to their finite battery life, requiring battery changes.
"Complications such as displacement, breakage, entanglement of the leads are not uncommon and could be catastrophic, the incidence of devices with bacterial infection keeps going up and, for paediatric patients, the device does not 'grow' with the patients.
"All these problems could be solved by a biological pacemaker."
Prof Jeremy Pearson, the British Heart Foundation's associate medical director, said: "The ability to turn ordinary heart cells into specialised pacemaker cells in this way is highly novel and scientifically fascinating.
"It opens up the tantalising possibility of using cell therapy to restore normal heart rhythm in people who would otherwise need electronic pacemakers.
"However, much more research now needs to be done to understand if these findings can help people with heart disease in the future."