The nerve to the obturator internus and the associated superior gemellus muscle originates from the ventral divisions of L5 to S2 and leaves the pelvic cavity through the greater sciatic foramen inferior to the piriformis muscle. Like the pudendal nerve, it passes around the ischial spine and through the lesser sciatic foramen to enter the perineum and supply the obturator internus muscle from the medial side of the muscle, inferior to the attachment of the levator ani muscle.