Sildenafil works by inhibiting the enzyme phosphodiesterase type 5 (PDE5), which increases the levels of cyclic guanosine monophosphate (cGMP). This leads to the relaxation of smooth muscles in the blood vessels of the penis, allowing for increased blood flow and enabling an erection when sexually stimulated.