This story is familiar to me as a common convention in the genie in the bottle fantasy tales.
"I am one of those spirits who rebelled against the sovereignty of Allah. All the other Genii acknowledged the great Solomon, the prophet of God, and submitted to him. Sacar and myself were the only ones who disdained to humble ourselves. In revenge for my contumacy, this powerful monarch charged Assaf, the son ofBarakhia, his first minister, to come and seize me. This was done; and Assaf captured me, and brought me by force before the throne of the king, his master.
"Solomon, the son of David, commanded me to quit my mode of life, acknowledge his authority, and submit to his laws. I haughtily refused to obey him; and exposed myself to his resentment rather than take the oath of fidelity and submission which he required of me. In order, therefore, to punish me, he confined me in this copper vase; and to prevent my forcing my way out he put upon the leaden cover the impression of his seal, on which the great name of Allah is engraven. Thereupon he gave the vase to one of those Genii who obeyed him, and orderedthe spirit to throw me into the sea; which, to my great sorrow, was done directly.
"During the first period of my captivity, I swore, that if any man deliveredme before the first hundred years were passed, I would make him rich, even after his death. The time elapsed, and no one released me. During the second century I swore, that if any one set me free, I would discover to him all the treasures of the earth; still no help came. During the third, I promised to make my deliverer a most powerful monarch, to be always at his command, and to grant him every day any three requests he chose to make. This age, like the former, passed away, and I remained in bondage. Enraged at last, to be so long a prisoner, I swore that I would without mercy kill the person who should release me; and that the only favour I would grant him, should be the choice of what manner of death he preferred."
Irish lore claims that the Otherfolk (Daoine Sìth - aka elves, esp.) are angels, or the descendent of angels, who chose to take no part in the rebellion of Lucifer, either to defend or attack the Heavenly throne. IIRC, they chose to either hide on, or remain on earth, and for that they were condemned to ... remain on earth.
This story (#3 in Arabian Nights - The Fisherman) indicates that the Genii were the rebellious angels - what Christians term demons - who repented ... or were forced to submit to punishment ... for their rebellion.
I tend to equate the Genii with the Daoine Sìth, the helpful ones with the Light/Summer Court, the dangerous ones - like this one - with the Dark/Winter, so the similarity of the origin tales interests me. I don't like that the Genii are considered to be Fallen Angels; I much prefer the Irish idea.