This is something for which you need to go to the ER.
You are having paraphimosis.
This is when the foreskin remains in a retracted position and cannot be pulled back over the glans penis.
It causes constriction of blood flow to the glans which swells up.
This is something which must be treated urgently as blood flow is restricted.
You have to go to the ER immediately or you will have very severe pain with possible damage to the glans penis.
For now, you should take the following steps:
Ice: apply ice to the area of the foreskin, not the glans. Take an icecube in a handkerchief and apply it. But dont apply for too long.
Bandage: apply a firm bandage which is not too tight on the foreskin. It should not be too tight.
These two steps will help till you get to the ER.
But you should go ASAP.