Finasteride prevents hair loss by inhibiting the enzyme 5-alpha-reductase, which is responsible for converting testosterone into dihydrotestosterone (DHT). DHT is a hormone that contributes to hair follicle shrinkage and the subsequent thinning and loss of hair, particularly in male pattern baldness.