Coral reefs are constantly assaulted by algae which wish to steal prime sunlit locations for themselves. To gain control, many of these seaweeds pack toxins that take a toll on coral metabolism.
Left unchecked, seaweed can smother coral and take over a reef; an often-irreversible demise.
Gobies and other herbivorous fish live among the coral, which produces mucus to feed them. When coral is being damaged by seaweed, it lets loose a chemical cry for help. Sensing distress at home, gobies gobble the algae.
For a goby and others, seaweed may be a fine snack, but it does not provide a reliable food source and a place to live like a coral reef. Herbivorous fish are critical in keeping the algae on reefs in check; hence, coral provide for police protection.