All organisms are constantly exposed to foreign chemicals every day. These can be man-made (drugs, industrial chemicals) or natural (alkaloids, toxins from plants and animals). Uptake is usually via ingestion but inhalation and transdermal routes are also common.
The very nature of many chemicals that make them suitable for uptake by these routes, in other words their lipophilicty (favours fat solubility) is also the main reason organisms have developed mechanisms that convert them to hydrophilic (favours water solubility) compounds which are readily excreted via bile and urine. Otherwise, lipophilic chemicals would accumulate in the body and overwhelm defense mechanisms. This process is called biotransformation and is catalyzed by enzymes mainly in the liver of higher organisms but a number of other organs have considerable ability to process xenobiotica such as kidneys, gut and lungs. As well as xenobiotics, many endogenous compounds are commonly eliminated by this process.
This mechanism is of ancient origin and a major factor for its development in animals is plants. Most animals are plant eaters and thus are subject to a huge variety of chemical compounds which plants produce to stop themselves being eaten. This complex set of enzymes have several features which make them ideal for biotransformation;
(1) metabolites of the parent chemical are usually made more water soluble so it favours rapid excretion via bile and urine
(2) the enzymes possess broad and overlapping specificity to be able to deal with newly exposed chemicals
(3) metabolites of the parent generally don't have adverse biological effects.
In the real world however, all these criteria have exceptions. Many chemicals are transformed into reactive metabolites. In pharmacology, the metabolites of some parent drugs exert the desired pharmacological effect but in the case of polycyclic aromatic hydrocarbons (PAHs), which can undergo epoxidation, it results in the formation of an electrophile which can attack proteins and DNA.
Metabolism of xenobiotica occurs in several steps called Phase 1 (functionalization) and Phase 2 (conjugation). To improve water solubility, a functional group is added to or exposed on the chemical in one or more steps (Phase 1) to which hydrophilic conjugating species can be added (Phase 2). Functional groups can either be electrophilic (epoxides, carbonyl groups) or nucleophilic (hydroxyls, amino and sulfhydryl groups, carboxylic groups) (see picture).
Once chemicals undergo functionalization, the electrophilic or nucleophilic species can be detrimental to biological systems. Electrophiles can react with electron-rich macromolecules such as proteins, DNA and RNA by covalent interaction whilst nucleophiles have the potential to interact with biological receptors. That's why conjugation is so important as it mops up these potentially reactive species.
Many chemicals, when exposed to certain metabolizing enzymes can induce those enzymes, a process called enzyme induction. The effect of this is that these chemicals accelerate their own biotransformation and excretion. The reverse is also true where some chemicals cause enzyme inhibition. Some other factors that alter enzyme levels are sex, age and genetic predisposition. Between species, there can be considerable differences in biotransformation ability which is a problem faced by drug researchers interpreting toxicological results to humans.