Grass plays a crucial role in the ecosystem by preventing soil erosion, providing habitats for various organisms, and serving as a food source for herbivores.