Along with taking away from power to the pedals, any extra body movement outside of the legs (head bobbing up and down, hips swaying side to side) can cause you to work muscles that shouldn’t be being worked, adding extra muscle fatigue and… you guessed it… losing energy that could have been used to help you push harder!
Generally speaking, the best way to “fix” this problem is to strengthen your core… OR engage it.