Earthworms are tubular, segmented Annelids; closely related to marine worms and leeches. These worms are often termed ecosystem engineers because they provide two main services to the wider ecosystem.
They do wonders for the soil. Their wriggling and squirming encourage the movement of water and minerals, aerating the soil as they go. These processes cause large pieces of organic matter to be broken up into a more useful byproduct known as humus, ultimately improving the fertility of the soil!
In addition to this, they're a primary resource for many garden creatures, including mammals, reptiles and birds.