Similarity between a heart attack and a spasm
I was able to do some reading and research and I found some interesting information that was a). news to me. And b). the answer is yes... And no.

A spasm can be the cause of a heart attack by causing the coronary artery to contract. When that artery contracts, it causes a dramatic decrease in blood flow to the heart. When the heart looses access to oxygenated blood it can cause chest pain (angina) or even an MI (Myocardial Infarction a.k.a. a heart attack). This spasm is can be caused by exposure to extreme cold, smoking and the use of certain recreational drugs.

However, this type of spasm cannot be stopped with defibrillation. Treatment for these involves administering Nitroglycerin and then later treatment involving Statin drugs and such.

In the terms you are speaking of, I don't see that that would be quite accurate. The most common cause of sudden cardiac death is VF (Ventricular Fibrillation) which is essentially an uncontrollable quivering of the heart muscle. I've never heard this described as a spasm though. Google searches of spasm and heart spasm have all lead to definitions of the word spasm and the coronary artery spasm mentioned above. 

However, within that, I think you have a valid point and a decent understanding of how things work, just perhaps not fitting under the definition of a spasm.

When a defibrillator is used, it delivers a measured electrical shock to the person's heart and hopefully stops the chaotic electrical rhythm. I'm not sure if this part is correct however, I do not think you should look at that as a stretching of the muscle though. It is an electrical intervention that interrupts the former rhythm and hopefully the heart "forgets" what it was doing and returns to a sinus rhythm.

So, to summarize: A heart attack can be caused by a spasm; however, defibrillation does not help that type of attack. A defibrillator does not 'stretch' the heart but rather interrupts it's former rhythm. Because an irregular heart beat is not considered a spasm, I find it difficult to believe that any form of EMP would help it; however, I would love to hear that it has!

For more information on Ventricular Fibrillation, CAS (Coronary Artery Spasm) and AED's (Automated External Defibrillator(s)). Please see the following:

MedlinePlus - on V-fib

The Mayo Clinic - on CAS

HeartSine - on AED's

I hope this was helpful for you!

Edits:

In the comments, we had discussed a variety of possible causes and treatments for spasms, as well as what - if any - connection there is between how a spasm in perhaps a leg would be caused as compared to how one in your heart could be caused. 

From the reading and research I did, I was fairly inconclusive about the safety or desirability of a device to prevent heart attacks using an EMP device implanted in your brain or on your brain stem. 

As far as how similar a spasm in your heart is to a spasm in any other muscle, they are not very similar. As seen here, a muscle spasm in most parts of the body can be caused by numerous things, such as dehydration, poor blood circulation, mineral deficiencies etc. Whereas a heart spasm (know as a CAS) can be caused by alcohol withdrawal, stimulant use, extreme cold... As seen here.