Ahhhhhhhhhh, so, the bike was upside down. Now it all makes sense.
That's a salient point that should have been included in the OP. When a bike is upside down, the chain is not under tension therefore gears won't shift properly and the chain will jump around.