earthworms respire through their skin and they must coat themselves in mucus to allow dissolved oxygen to pass into their bloodstreams. like most all land-based animals, earthworms cannot breathe underwater so when you see them emerge from the ground after a deluge rain they are merely trying to find oxygen to breathe just like any other animal would