In this context, a likely cause is salt depletion from dehydration which would explain the spasming. Additionally, although it may not be 'over-exercise', your body may have just run out of the energy needed to relax your muscles, and therefore your muscles spasmed.
If you go into the same position again and you repeatedly begin to feel pain, go see a doctor.
To prevent it? Drink fluids and don't skip your preworkout meal.
If you have a tendency to cramp up, then vitamin E and calcium supplements may be in order. I've had some stretches of time were I would randomly get cramps at night...like when your hamstring locks up. Although painful as hell, taking some magnesium helps.