I have always twitched like this, and I formed a theory about it during my sleep clinic elective.
During REM sleep, some of which occurs not long after falling asleep, our mind is going like a bat out of hell but our body is paralyzed. It is during this time that we dream, and the paralysis is what prevents us from acting out our dreams.
Some people, particularly those with narcolepsy (of which I have mild symptoms), have a blurring of the lines between the stages of sleep. Thus, if you’re having a dream and suddenly go from REM sleep to a different stage, you will suddenly start acting out the dream with a twitch. This usually wakes people up. It’s only a theory, but seems reasonable to me.
You didn’t ask, but the difference between a nightmare and a night terror is that night terrors occur during non-REM sleep, so they can be acted out. They are also not remembered as well, and are usually only remembered as a sense of dread without the detail of a nightmare.