Secondary in contrast to primary metabolites are dispensable and not absolutely required for survival. Furthermore, secondary metabolites typically have a narrow species distribution.
Secondary metabolites have a broad range of functions.  These include pheromones that act as social signaling molecules with other individuals of the same species, communication molecules that attract and activate symbiotic organisms, agents that solubilize and transport nutrients (siderophores etc.), and competitive weapons (repellants, venoms, toxins etc.) that are used against competitors, prey, and predators. For many other secondary metabolites, the function is unknown. One hypothesis is that they confer a competitive advantage to the organism that produces them. An alternative view is that, in analogy to the immune system, these secondary metabolites have no specific function, but having the machinery in place to produce these diverse chemical structures is important and a few secondary metabolites are therefore produced and selected for.
General structural classes of secondary metabolites include alkaloids, phenylpropanoids, polyketides, and terpenoids.