In an ecosystem, fungi play the role of decomposers -- they break down dead organic matter and return vital nutrients to the soil.
Decomposers are important in the food chain because they break down dead organisms and recycle nutrients into the soil.