Pain in the anus is often caused by anal fissure
. This is a break of anus mucosa in your case caused by putting pressure on your anus when tighten anal sphincter. Anal fissure is often caused by constipations. If there is some fresh(bright red) blood in your stool, this is what you are suffering from. The pain may last from few days to couple a weeks. However sometimes anal fissures may become chronic.
What you should do, is to avoid constipations(eat food rich in fibers, drinking enough water, and do more exercises) and hard pushing on stool, have some hot baths of this area and your mucosa wound should be self-healed. Sometimes nitroglycerin
salve might be necessary or calcium channel blockers intake.
In chronic anal fissure surgery might be necessary.
Hope this will help