Well if there was any kind of anal penetration then YES you could be at risk for contracting HIV however if there wasn't any penetration then the risk would be very low. One thing to note would be that , if the other person's penis did touch the mucous membranes of the anus then there is a risk for HIV. If there was no contact between his penis and the inner part of your anus, then again the risk would be low.
According to one study, if there is actual anal penetration and the other person is HIV positive then the risk for transmission is approximately 40%. However if there is no penetration then the risk drops significantly.
So according to this, since there wasn't any real penetration (meaning the penis did not touch the inner side of the anus) then you are NOT at high risk for transmission. However you are still at a normal risk for acquiring HIV depending on what other sexual acts you performed. (for example Oral sex has a risk of less than 0.04%). It would be wise to get screened for HIV after 4 weeks, as sexually active adults should get the screening done atleast once a year.( i.e If you haven't had the screening done as of yet).
I hope I have been helpful and this answers your query. Please remember to assign a feedback rating so JA will compensate me for my time. You are free to ask follow-up questions thereafter at no charge although any bonuses would be appreciated. Please allow up to 24 hours for a follow-up response if I am signed off.
If, for some reason, you are not satisfied with the answer, I would appreciate knowing why so that I can try to clear up any misunderstanding that may have taken place and still earn a positive rating from you. Finally, you may request me in the future by beginning the question with "THIS IS FOR Dr. Muneeb Ali".
Thank you for using Just Answer.