Of course that gravity is pulling on the mercury.
Do this experiment: take a big 2l bottle and fill it to the brim with water. Now turn it upside down very quickly. You will see that the water will have a hard time coming out, and the air going in, making the water come out in pulses. This is because to get water out, air has to take water's place, and the only way it can do that is by bubbling up through the water, which takes time. With water and mercury, the situation is so much worse that it is metastable: water will not be able to bubble up to the top of the mercury column, and the liquids stay in place.
(While you are making the experiments with the bottle of water, try this: after turning it upside-down, make a quick circular motion horizontally, to create a whirlpool of water inside the bottle. You will see that the water now flows out very smoothly. This is because the whirlpool creates a "hole" in the middle of the water and air can easily flow in.)