My dh and I had a bad case each of the "twitches" the other night. Neither his legs nor mine would stop twitching for quite some time, and even getting up and walking around did not help. It made sleeping impossible until finally our legs calmed down.
There is a syndrome called Restless Leg Syndrome. If it continues you need to see a doctor. There are prescription medications to help.
My husband and I get the same thing, if you have a massager, take turns massaging each others legs, it will work the twitching out enough for you to go back to sleep. Then the next morning start eating bananas to get your potassium, drink some milk for the calcium and increase you magnesium.
The fix may depend on what type of problem is causing the twitching.
For me, magnesium tablets and icing daily helps a bit to relax the muscle...but I have a compressed nerve under my calf. This twitching is caused when I feel like my leg is like a winch being pulled tighter, and tighter, and tighter until it explodes!
Other suggestions by my doctor was tonic water (also known as quinine water) nightly, daily doses of major electrolytes (in my case, drinking a 12 oz portion of the lower calorie Gatorade), etc.
In my younger days, I would have muscle cramping that would be severe enough to lead to twitching. Potassium usually helped.
But I would strongly suggest visiting a doctor when possible. There are many different causes of leg twitching and you might need physical therapy to correct them as well.
I was in a coma 3 years ago and when I woke up and began recovery for multiple organ failure I had the same problem. The doctors prescribed 500 mg magnesium tablets, and increased my calcium intake. I try to get calcium in my diet, the magnesium is available at most drug stores.