Molecules in a gas move randomly because they undergo 'collisions' with each other.These collisions are nothing but repulsion of like charges. As the colliding molecules move further apart there is no force in gases which counters this repulsion.In liquids the cohesive forces(which are also em in nature) counter the repulsions to some extent.So gases try to occupy as much space as possible.But in spite of this spread, gravity does ultimately manage to hold the molecules together to some extent. If it was'nt so, the atmosphere would not stick to the Earth and niether would the oceans!