The mechanism during an immune response that produces antibodies with a strong ability to bind to a foreign antigen over time. Affinity maturation is produced by changes in the genes that encode immunoglobulin G (IgG) and by increased survival of those B lymphocytes that produce antibodies with the greatest ability to destroy a particular antigen. Increased affinity occurs only when B-cell activation is stimulated by helper T cells.