Mushrooms are fungi. They are heterotrophs (they cannot make their own food) and must digest substances outside themselves to obtain nutrients and energy. Animals, including humans, are also heterotrophs.
The mushroom is only the fruiting body of a much larger organism, a huge network of tiny threads, called hyphae. Fungi live inside their food, secreting enzymes that digest it, and then absorbing nutrients. When the time is right, fungi grow mushrooms to produce and spread their spores.
Mushrooms are one of the few organisms that can decompose lignin, the chemical that makes woody plants so tough. If all lignin-digesting fungi went extinct, dead woody plants would not decay, but collect and begin to pile up. Mushrooms thus play an essential part in ecosystem function.
Fungi are not just decomposers. Some form symbioses -- mutually beneficial relationships -- with other organisms. For example, "mycorrhizal" fungi partner with trees, getting sugar from the roots and giving the plant nutrients. Many edible mushrooms are mycorrhizal.