Trimethoprim's mechanism of action involves competitive inhibition of the bacterial enzyme dihydrofolate reductase. By binding to the active site of this enzyme, trimethoprim prevents the conversion of dihydrofolic acid to tetrahydrofolic acid. This inhibition is crucial because tetrahydrofolic acid acts as a cofactor in the synthesis of nucleotides, which are building blocks for DNA. The selective binding of trimethoprim to bacterial, rather than human, dihydrofolate reductase makes it an effective antibiotic.