Hi there. Did you sustain any trauma to the back recently that could have caused prolapsed lumbar disc and some local tissue injury causing tenderness at the back? This could cause muscle spasms causing the movement. There are certain causes responsible for muscle twitching like diet deficiency, drug overdose, and side effects of diuretics, corticosteroids, estrogens, exercise, benign twitches, and nervous system conditions like amyotrophic lateral sclerosis or ALS, muscle dystrophy, spinal muscular atrophy and myopathy. Your neurologist needs to look into these conditions one by one. The other possible cause could be multiple sclerosis and is a diagnosis of exclusion. Restless leg syndrome also needs to be looked into. Hope these speculations help. Take care.
Normally this happens when a person hasn't been getting enough deep REM sleep. The body and mind are starved for complete rest, and if they don't get it, and you finally relax enough to fall asleep, the tired person releases all this built-up stress in a huge jerking around thing. But just to make sure, you could visit a neurologist to check you for possible seizure problems developing. But if you will figure out why you are not sleeping well and correct it, and you don't have any further thrashing about, then I think you can chalk this up to your lack of good rest. By the way, some medications will affect REM sleep or deep sleep levels, so check side effects of anything you take or ask the prescribing doc about your drugs and effect on deep sleep. Also, exercising regularly will generally help a person sleep better and release stress, so you could get into that, if you already aren't, and could be that will help you.