Methotrexate inhibits the enzyme dihydrofolate reductase, which is essential for DNA synthesis and cell reproduction. This leads to the suppression of rapidly dividing cells like cancer cells and immune cells involved in autoimmune diseases.