God created perfect angels and he gave them free will. The angel who made himself Satan the Devil was an angel of high ranking, "an anointed covering cherub." Ezekiel 28:12b-14.
This angel used his free will to allow a destructive inclination to grow in himself. He became jealous/covetous of and desirous of the worship that belonged only to God. His unrighteousnes (Ezekiel 28:15) led him to become the Deceiver. He also became the one who is the Resister, the one in opposition to God.
How is this possible.
Free will is a gift from God to all intelligent creatures. Angels are intelligent creatures as are humans. For example: No one can make a thief a thief except the person who has the idea/desire to become a thief. This is what happened to the angel who became Satan the Devil. His desire turned into his reality. James 1:14,15 "But each one is tried by being drawn out and enticed by his own desire. 15 Then the desire, when it has become fertile, gives birth to sin; in turn sin, when it has been carried out, brings forth death."
It is a powerful study to learn more about this one who was a "covering angel" and why he was present in the garden of Eden. (Ezekiel chapter 28)
Visit
www.wol.jw.org/en and enter "covering angel" in the search box and look for the article Watchtower 1954 titled WHY GOD PERMITS EVIL. You will probably want to read the entire article but pay special attention to the information under the subheading "Man's creation and deflection."
Hope this helps.