The contents of the colon are moved along by peristalsis. Peristalsis creates a high pressure when the smooth muscles of the colon contract in a small area. The contents of the colon move along towards a lower pressure, towards the anus, the gas being more mobile than the rest of the contents moves along quicker and also tends to coalesce into larger and larger bubles. The colon also absorbes water making its contents less and less runny.
Peristalsis in the colon is stimulated by eating and drinking which is why we have a desire to pass gas a little while after eating. There is an interesting ring of nerve endings just inside the anus, called White's ring if I remember correctly, which is able to distinguish between solid, liquid and gas. This lets us pass gas without soiling our pants, most of the time.