Muscle spasm (i.e. muscle cramp)
I have had muscle spasms during training and a marathon. All of them were most likely caused by severe loss or imbalance of electrolytes. Appropriately replenishing body with electrolytes is naturally the most effective way of preventing muscle spasm.
The most important thing do do after a spasm occurs is immediate rest. Muscle spasm causes little damage by itself. Most damage is usually caused by continuing use of the muscle in spasm. Even very light use of the muscle in spasm for 10 to 20 minutes can result in requiring one to two weeks of recovery time. Immediate rest and letting the muscle relax naturally or via massage will lead to complete recovery within the same day.