Introduction. Androgen receptor (AR) CAG polymorphism has been found to influence sexual function. However, no study has evaluated its potential to condition sexual function recovery after testosterone replacement therapy (TRT) in a large cohort of hypogonadic subjects. Aim. To evaluate the role of this polymorphism in sexual function improvement after TRT in late-onset hypogonadism (LOH). Methods. 73 men affected by LOH were retrospectively considered. Evaluations were performed before TRT started (time 0) and before the sixth undecanoate testosterone injection. Main outcome measures. International Index of Erectile Function questionnaire (IIEF) [erectile function (EF), orgasmic function (OF), sexual desire (SD), intercourse satisfaction (IS), overall satisfaction (OS) and total IIEF-15 score]; total and free testosterone and estradiol; AR gene CAG repeat number. Results. TRT induced a significant increase in total and free testosterone and estradiol. All IIEF domains significantly improved after TRT. AR CAG repeats negatively and significantly correlated with all the variations (Δ-) of sexual function domains, except for Δ-OS. Conversely, Δ-total testosterone was found to be positively and significantly correlated with sexual function domain variations, except for Δ-IS and Δ-OS. Δ-estradiol did not correlate significantly with any of the variations of sexual function domains. After inclusion in generalized linear models, the number of AR gene CAG triplets was found to be independently and negatively associated with ∆-EF, ∆-SD, ∆-IS and ∆-Total IIEF-15 score, whereas ∆-total testosterone was independently and positively associated with ∆-EF, ∆-OF, ∆-SD, and ∆-Total IIEF-15 score. However, after including time 0 total testosterone in the model, AR gene CAG triplets remained independently and negatively associated only with ∆-EF and ∆-Total IIEF-15 score, whereas ∆-total testosterone was independently and positively associated only with ∆-EF. Conclusions. Longer length of AR gene CAG repeat tract seems to lower TRT-induced improvement of sexual function in LOH.