Most likely the cam sensor has failed. That can make an engine run poorly, shake and make a lot of unsettling noises. Wouldn't be a bad idea to check the condition of your timing belt and make sure its timed right as well. Its extremely unlikely that the sensor became loose. Good luck!