A muscle cramp is a painful, sudden, and sustained contraction of skeletal muscle fibers. It is usually associated with electrolyte imbalance, including hypomagnesemia. Overuse of a muscle, muscle strain, dehydration, or simply holding a position for a prolonged period may lead to a muscle cramp.