A muscle spasm is an involuntary contraction of a muscle and is frequently painful. There are many different types of muscle spasms. Muscle spasm results from inflammation that occurs when a muscle is overstretched or torn. A contraction can last for a few seconds, to several minutes or hours.