People at risk of heart disease are often told to exclude sweet and fatty foods from their diet.
But the researchers said chocolate seems to have 'antioxidant, anti-inflammatory and antiplatelet properties' - which help reduce the risk of developing heart problems.
Abnormal heart rhythm, known as atrial fibrillation, affects up to 900,000 patients in England and causes the heart to beat very fast and irregularly, greatly increasing the risk of stroke and early death.
The scientists think flavanoids - natural antioxidants found in cocoa - ward off the condition by reducing blood pressure, cholesterol and inflammation.
The team, which tracked 55,000 people in Denmark for 13 years, did not look at whether the participants were eating milk or dark chocolate, which contains more cocoa.
But they wrote: "Most of the chocolate consumed in Denmark is milk chocolate.
"Despite the fact that most of the chocolate consumed in our sample probably contained relatively low concentrations of the potentially protective ingredients, we still observed a robust statistically significant association."
And they said dark chocolate probably has an even greater protective effect, the journal BMJ Heart reports.
Victoria Taylor, dietitian at the British Heart Foundation, said: "Although this is a large study, it is only observational and so other factors could also be responsible for the effects seen."
Dr Tim Chico, consultant cardiologist at the University of Sheffield, added: "When a health story seems too good to be true, it sadly usually is.
"One in four of us will develop atrial fibrillation by the age of 80. The best way to avoid this is to maintain a healthy weight and blood pressure, perform moderate exercise regularly, and reduce alcohol intake."