Both water and ammonia molecules are capable of hydrogen bonding (H attached to O, and H attached to N, respectively). When ammonia gas is first bubbled into a sample of water, the ammonia molecules begin to hydrogen bond to the water molecules and to draw the water molecules closer together than they would ordinarily because of the increased intermolecular forces.