You do this by denying who you are, covering up awareness of who you are, and displacing your sense of self onto anything that you perceive as "not me".
What you do is you take part of your mind and retain it as conscious awareness (your persona), and then shield it from the rest of your mind which becomes unconscious (your shadow).
The unconscious part of the mind is disassociated from, denied and rejected. You hide it from yourself so that you can pretend to be only a limited identity.
What is then part of your own unconscious mind then seems to "project" outward, creating hallucinations of an external world. Since you've placed a barrier between your conscious awareness and "the rest of yourself", you do not experience what's out there as yourself.
So now it seems like there is an entire world that is not you, filled with identities and people who are not you.
At the same time, in order to disown yourself, you have to give ownership of yourself away. That means your sense of identity has to become the possession of some other self, namely the ego.
It is not that the ego has any power of its own to take possession of you. Your attempt to disown your own self produces the ego. You make it everything it is on purpose. And yet at the same time as disowning yourself, you appear to grant it permission to possess you.
It seems then that the ego is a separate entity, largely in your unconscious, filled with all the unwanted parts of yourself which you judge as unacceptable, wrong, bad, guilty etc. Yet at the same time, the ego is also in the conscious persona which is at war with the unconscious. It is the separation between them that is the ego.
This unconscious repository of darkness is your "pain body". At times your pain body, the emotional body of the ego, will take possession of your conscious mind/persona, becoming extremely anti-persona and believing the exact opposite of what the persona-self believes.
When this happens it quite literally is like being possessed by some kind of dark twisted being who is very strongly in denial, very deeply opposed to any kind of truth, and it can flood the mind with negative fearful thoughts.
It in a way feeds off of you, in that by throwing your own repressed stuff into your awareness (ultimately as an act of attempted healing), your mind becomes overwhelmed with fearful reactions and this generates a negative energy which it appears to feed off.
Depending on how much separation you have experienced in your existence, will somewhat determine the 'body' of pain i.e. everything you judged or rejected, which has become stored any our unconscious and which needs to be purified and released.
Going through this process is often something that is randomly triggered and seemingly unwanted and horrifying, because it is as though a person can become literally possessed by some dark being, losing significant awareness, going into an unconscious state of paranoia and fear and guilt and dwelling upon the past.
For some people the pain body is so strong that it can produce violence and suffering, while for others it may come and go more quickly. It returns to being somewhat dormant if the person is able to maintain a non-reactionary consciousness, i.e. awareness. But if it is allowed to take over awareness it can turn a person into seemingly someone possessed, who you may barely recognize, and who may suddenly become what many people would consider either depressed or mentally ill.
These periods of "release" of unconscious dark baggage are punctuated after a usually short period of time with a period of relief in which a lightness and happiness takes over. This is similar to what happens when you have a cathartic cry, which initially is painful and dark and upsetting to go through, but at the end once the energy is cleared out you may find yourself laughing.
Ultimately this is a process of healing and release and a way for a person to let go of a large body of unconscious pain which needs to be permitted, allowed, accepted and observed, without becoming too lost in the clouds along the way. Since we repress a great amount of negativity into the unconscious, or otherwise known as the "shadow", there can be a lot of self abuse to be cleansed.
Ultimately the ego itself is not an entity and nor can it truly possess you against your will, but since it is something that you yourself set in motion and gave power to, you have to go through a process of allowing the shadow and persona to cancel each other out. The conscious mind is overcome by what appears to be mind-altering and even behavior-altering unconsciousness, but it is only happening because the person has become ready to work through their baggage and release it.
If this is happening to you or to people you know, you might think they are crazy or that something terrible has happened medically. No many people understand this. But at some point sooner or later you as you progress on your steps towards returning to your true self, reclaiming your identity, waking up to reality and accepting God's truth, it's going to mean you need to purify and flush out all of the ways in which you have created separation in yourself, and so it's as though the lid is lifted off your denial, producing a profound release. And so this really is a part of the awakening process.
This may be the way that you proceed in your path, to varying degrees, or it may not be. It can be very difficult and extremely confusing to go through. But we are all heading home to God one way or another and for some people it takes a direct expression of unconscious fear, guilt and rage, in order to cleanse the mind of the darkness which has been stored there. We all have our skeletons and we all could use a closet spring-clean.
None of use are stuck in the ego. Nobody is a victim of evil. Nothing is happening in our mind that we haven't put in place. And our own ego, our alternate identity, is just a part of our own self that we've pretended to split off. It is no more a separate entity than that it is our own self pretending to not be our own self. And so it's an interesting paradox that as we attempt to disown ourselves, we become owned by ourselves, albeit around a wall of unawareness. Moral of the story being, you cannot stop being what God created.
We're all loved by God and there is no real way to be separate from Him.