The pain is most likely caused by the hemmoroids (piles) but it could also be anal fissure. I have had both. Anal fissure is just a tiny tear in your anus that causes a lot of pain. I was in pain constantly, day and night. My usual over the counter suppositories for piles weren't helping. I also convinced myself Ive cancer. I went to the specialist who looked more closely (I know!) and gave me different suppositories.
If your pain continues, you should go to the doctor and get checked out and get prescription strength suppositories. Good luck!