Rectum

The rectum (Latin for "straight") is an 8-inch chamber that connects the colon to the anus. It is the rectum's job to receive stool from the colon, to let you know there is stool to be evacuated, and to hold the stool until evacuation happens. When anything (gas or stool) comes into the rectum, sensors send a message to the brain. The brain then decides if the rectal contents can be released or not. If they can, the sphincters (muscles) relax and the rectum contracts, expelling its contents. If the contents cannot be expelled, the sphincters contract and the rectum accommodates, so that the sensation temporarily goes away.
The anus is the last part of the digestive tract. It consists of the pelvic floor muscles and the two anal sphincters (internal and external muscles). The lining of the upper anus is specialized to detect rectal contents. It lets us know whether the contents are liquid, gas, or solid. The pelvic floor muscle creates an angle between the rectum and the anus that stops stool from coming out when it is not supposed to. The anal sphincters provide fine control of stool. The internal sphincter keeps us from going to the bathroom when we are asleep, or otherwise unaware of the presence of stool. When we get an urge to go to the bathroom, we rely on our external sphincter to keep the stool in until we can get to the toilet.

Reference:

https://www.webmd.com/heartburn-gerd/your-digestive-system#3
https://www.google.com.ph/search?q=digestive+system&rlz=1C1CHBD_enPH815PH818&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjV7ePTofneAhWZc3AKHULjBHAQ_AUIDigB&biw=1366&bih=657#imgrc=ksyAxqDly7Z4WM: