There is only one cog which naturally "wants" to align with a given chainring; you chose the cog next to that one, which is why the chain "insisted" on moving over. You are fortunate it did not do any damage in the process, the forces can be surprisingly high.