The chemical reactions and pathways resulting in the formation of aflatoxin, a fungal metabolite found as a contaminant in moldy grains that induces liver cancer. Aflatoxin induces a G to T transversion at codon 249 of p53, leading to its inactivation. Aflatoxin is converted to a chemical carcinogen by P450.