The sea cucumber ejects part if its inner organs for the predator to eat while it escapes.
I believe it does that because the innards are incredibly sticky and caustic and gets tangled in the predators face and jaws. Although it might depend on the species. Seems to be some misconceptions about this and I could be the wrong one.
The hagfish excretes a very thick mucous that chokes a would-be predator. There are plenty of amazing videos. A single scrape of its slime added to a bucket of water can turn that into a gelatinous blob.
Hagfish Slime
As far as animals defecating on themselves in defense, I have never heard of this (organismal biology bachelors here). However, it is not unheard of that animals defecate on a kill after eating their share, or to prevent a scavenger from stealing the food. It is not defensive, but a more of a middle finger to any scavengers that are about to succeed in driving them away from their kill.
Octopi and squid can squirt a nasty tasting, temporarily blinding, and clouding ink into the water to escape. It's less disgusting to us, but probably yuck to a predatory fish or cetacean (whale/dolphin).
Bombadier beetles squirt boiling hot chemicals at a predator. It can be very painful and cause small, localized 3rd degree burns.
Some tarantulas flick their incredibly irritating abdominal hairs at the eyes of enemies.
Many, many animals - especially reptiles, pee on something they perceive as a threat. If grabbed in a mouth, suddenly urinating on the predators tongue is an effective and disgusting defense.
Many snakes excrete a musk that is incredibly nasty smelling, when threatened.
And there are less disgusting defenses as well. Many people don't realize that there are poisonous mammals. The Cuban Solenedon and male Platypus are interesting examples.