Earthworms respire (“breathe”) by absorbing oxygen through their body surface into the body and sending carbon dioxide out. The oxygen dissolves in the mucous on the body surface and then passes into the highly branched capillary blood vessels in the body wall where it is picked up by the respiratory pigment and transported to the internal organs.
That is why it is important not to dry them out! What’s more is: Earthworms may survive for considerable lengths of time in water if the dissolved oxygen level is high enough.