Soft-bodied slow-moving sea creatures such as sea stars and sea cucumbers lack an adaptive immune system and have instead evolved the ability to make specialized protective chemicals (glycosylated steroids and triterpenes) as part of their innate immune system. This raises the intriguing question of how these biosynthetic pathways have evolved. Sea star saponins are steroidal, while those of the sea cucumber are triterpenoid. Sterol biosynthesis in animals involves cyclization of 2,3-oxidosqualene to lanosterol by the oxidosqualene cyclase (OSC) enzyme lanosterol synthase (LSS). Here we show that sea cucumbers lack LSS and instead have two divergent OSCs that produce triterpene saponins and that are likely to have evolved from an ancestral LSS by gene duplication and neofunctionalization. We further show that sea cucumbers make alternate sterols that confer protection against self-poisoning by their own saponins. Collectively, these events have enabled sea cucumbers to evolve the ability to produce saponins and saponin-resistant sterols concomitantly.