As the rectum passes through the pelvic diaphragm, it becomes continuous with the anal canal, which ends here at the anus.
The lower end of the rectum runs downwards and forwards, the anal canal runs downwards and backwards. The angulation between the rectum and anal canal, the perineal flexure, is maintained by the forward pull of the puborectalis part of the levator ani muscle.
Closure of the anal canal is maintained by the internal and external anal sphincter muscles. The involuntary internal sphincter is a continuation of the circular smooth muscle coat of the intestine. It's present in the proximal two thirds of the anal canal. The voluntary external sphincter runs the full length of the canal.
This is the external anal sphincter. It's somewhat funnel-shaped. Above, the external sphincter merges with the levator ani muscle. Its upper part consists largely of anular fibers that go all the way round.
Its lower part is formed mainly of fibers that pass from back to front. Behind, these fibers are attached to the anococcygeal ligament. In front they're attached to the perineal body, or central perineal tendon, which is here.
The levator ani muscle is shown in more detail in Tape 3 of this atlas.