It is a PDE5 inhibitor. It blocks the action of an enzyme which contributes to vascular smooth muscle constriction.
This causes blood vessels which are effected to relax and have larger lumens.
It was originally designed for pulmonary hypertension, which it still is used for in newborns and small children, but during drug trials it was found to be not very effective for that purpose.
It WAS found to provide relief for men with erectile dysfunction due to long term vascular disease, though.
It is now marketed almost exclusively for that purpose. Its use for pulmonary hypertension now represents a niche market in the pharmaceutical industry.