Testosterone is overwhelmingly important in regulating erectile physiology. However, the associated molecular mechanisms are poorly understood. The purpose of this study was to explore the effects and mechanisms of testosterone in erectile dysfunction (ED) in castrated rats. Forty male Sprague-Dawley rats were randomized to four groups (control, sham-operated, castration and castration-with-testosterone-replacement). Reactive oxygen species (ROS) production was measured by dihydroethidium (DHE) staining. Erectile function was assessed by the recording of intracavernous pressure (ICP) and mean arterial blood pressure (MAP). Protein expression levels were examined by western blotting. We found that castration reduced erectile function and that testosterone restored it. Nitric oxide synthase (NOS) activity was decrease in the castrated rats, and testosterone administration attenuated this decrease (each p < 0.05). The testosterone, dihydrotestosterone, cyclic guanosine monophosphate (cGMP) and cyclic adenosine monophosphate (cAMP) concentrations were lower in the castrated rats, and testosterone restored these levels (each p < 0.05). Furthermore, the cyclooxygenase-2 (COX-2) and prostacyclin synthase (PTGIS) expression levels and phospho-endothelial nitric oxide synthase (p-eNOS, Ser1177)/endothelial nitric oxide synthase (eNOS) ratio were reduced in the castrated rats compared with the controls (each p < 0.05). In addition, the p40(phox) and p67(phox) expression levels were increased in the castrated rats, and testosterone reversed these changes (each p < 0.05). Overall, our results demonstrate that testosterone ameliorates ED after castration by reducing ROS production and increasing the activity of the eNOS/cGMP and COX-2/PTGIS/cAMP signaling pathways.