A synthesised compound also found in bear bile may help the recovery of some people who have had a heart attack.
Ursodeoxycholic acid (UDCA) is already used to reduce cholesterol production, and to dissolve gallstones.
Now a study by London's Imperial College has shown it could also treat potentially dangerous abnormal heart rhythms.
Bear bile is used in many traditional Chinese medicines, but critics say the way it is collected is cruel.
The latest study shows that UDCA could prevent abnormal heart rhythm or arrhythmia, both in people who have had a heart attack, and in foetuses.
It alters the electrical properties of myofibroblast cells, which are present in the foetal heart and in patients who have suffered a heart attack.
The study found that myofibroblasts disrupt the transmission of electrical signals that control the heart's rhythm.
"These findings are exciting", said Dr Julia Gorelik, the study's senior author. "Our results from the lab suggest that UDCA could help the heart muscle conduct electrical signals more normally."
UDCA is already used to treat obstetric cholestasis, a condition which affects one in 200 pregnant women in the UK and is linked to a higher risk for the foetus of arrhythmia and sudden death.
The chemical lowers the levels of harmful bile acids which the disease causes, and which can pass into the infant through the placenta.
It is hoped that a clinical trial will demonstrate whether the results of this new research translate to patients with heart failure.
Commenting on the research, Peter Weisssberg, medical director at the British Heart Foundation, said: "This study provides some insight into how bile acids might cause fatal rhythm disturbances in foetal hearts. If the same mechanism applies to adult hearts after a heart attack, this could prove to be a useful treatment to prevent serious heart rhythm disorders."
Dr Jill Robinson, founder and CEO of Animals Asia said: "It is welcome news that synthesised UDCA may help in the treatment of abnormal heart rhythm and other heart conditions.
"Though UDCA can be found in bear bile, only synthetic compounds should be considered for human use, for medical, conservation and animal welfare reasons."