do you have that problem using andy or another rig?
If it's a rig that you are not limited by the mesh for the rotation and twist then it might be because you put too much rotation, more than 180. If it's a rig like andy, then I would think that the problem come from a gimble lock.
maybe you will find some usefull info on this link.
http://www.anticz.com/eularqua.htmMaybe you can try this:
In Graph editor-> Curves -> Euler Filter
This can sometimes fix the gimble problem very easily (if it is a gimble problem)