Mushrooms play a very important role in many different ecosystems. The fruiting bodies are a source of food for many different species, not just humans, and on a smaller scale, the mycelium digests and decomposes organic matter that may not be able to be used by other organisms.
But even more important, is a relationship called mycorrhizal symbiosis. In this relationship, the fungus grows around the roots of a vascular plant, and passes water and mineral nutrients to the plants in exchange for complex sugars created through photosynthesis.
The most common type, arbuscular mycorrhiza, is found in at least 70% of all plant species, including many crop species such as wheat and corn that humans rely on for survival. If you have nearly anything growing in your garden right now, you can thank mycorrhizal fungi for making it happen!