Background Sequelae after inguinal hernia repair include pain-related impairment of sexual function. Pain during intercourse can originate from the scar, scrotum, penis, or during ejaculation. The aim of this study was to investigate if the Onstep technique resulted in better results than the Lichtenstein technique regarding pain-related impairment of sexual function. Methods This study was part of the randomized ONLI trial (NCT01753219, Onstep versus Lichtenstein for inguinal hernia repair). Separate reporting of pain-related impairment of sexual function was planned before the study start, with a separate sample size calculation. Participants were randomized to the Onstep or Lichtenstein technique for repair of their primary inguinal hernia and followed up at 6 months postoperative with the use of a questionnaire specific for pain-related impairment of sexual function. Results A total of 259 patients completed the 6-month follow-up, 129 in the Lichtenstein group and 130 in the Onstep group. Among the patients operated with the Onstep technique, 17 experienced pain during sexual activity 6 months after operation compared with 30 patients operated with the Lichtenstein technique (P = .034). Both subgroups that experienced pain during sexual activity had a median visual analog scale score of 0 with an interquartile range of 0 to 2 (P = .349). The Lichtenstein technique resulted in new pain in 14 patients, whereas the Onstep procedure gave new pain in 7 patients (P = .073). Conclusion The Onstep technique was superior to the Lichtenstein technique in terms of pain during sexual activity 6 months after operation.