Tough to stop once it starts, some times you can find a "sweet spot" while moving your leg, pretty much if it happens you gotta ride it out. But an ounce of prevention is worth more than a pound of cure, stay hydrated and eat a banana every now and then. They are caused by dehydration and low potassium levels , I do this and it works for me. Good luck
It is a muscle spasm that occurs mostly in the leg. To stop the muscle pain; you have to stop your activity, try stretching and massaging the affected muscle. You can also use ice after the first spasm.