Question: Was Iblîs (Shaitan, the Devil) the master of angels before he was cursed?
Yes, he was the master and chief of angels. Islamic scholars declare:
All angels fell prostrate towards Âdam ‘alaihis-salâm with the command of Allahu ta’âlâ. Iblis, master of angels, did not obey the command and did not fall prostrate. According to a narration transmitted by Hadrat Imâm-i Salabî on the authority of Hadrat Ibni Abbas, Iblis was with angels. He was from the tribe of genies, who was created from fire. As for angels, they were created from nûr (light). The former name of Iblîs was Azâzil. He was one of the guards of Paradise. He was the chief of the angels who were in the sky which was the nearest to the Earth. He was the sultan [ruler] of the earthly sky and the earth itself. He was higher than angels in the grade of knowledge. He was administering the affairs of the part between the sky and the earth. For this reason, he became conceited. This state of his drifted him to disobedience to Allah. Allahu ta’âlâ, in turn, expelled him from His mercy. (Jâmiul Ahkâm)

Hadrat Ibni Abbâs declared:
(Iblîs was one of the guards of Paradise. He was administering the affairs of earthly sky.) [Bayhaqî]

Sâid bin Musayyib declared:
(Iblîs was the chief and master of the angels.) [Ibni Jarîr, Imâm-i Suyûtî]

It is proclaimed in the Qur’ân that it was angels who were ordered to fall prostrate. Although Shaitan was not given such an order, why was he punished and cursed?
It is not by any means possible for Allahu ta’âlâ to do something wrong or useless or to punish one of His innocent creature without notifying, that is, to inflict oppression. Iblis was living with angels, and he was their master. Allahu ta’âlâ ordered the community of angels, which also included Iblîs. If Iblîs had not been in that community, the order issued would not have applied to him. Since the Qur’anic verses say, “But Iblîs did not fall prostrate,” he was one of those who were ordered to make prostration. The purport of a verse is as follows:
(We said to the angels, “Fall prostrate before Âdam.” They all fell prostrate save Iblîs. He was one of the genies. He disobeyed the command of His Rabb. Are you now taking Iblîs and his cohorts as friends instead of Me? In fact, they are your enemies. How evil is the exchange [to give Paradise and to attain Hell instead by taking the followers of Shaitan as friends] on the part of the Zâlimûn.) [Sûrat-ul-Kahf, 50]

The purport of two ahâdîth reporting that Shaitân was commanded to prostrate himself is as follows:
(When son of Âdam reads the âyah [Qur’anic verse] of sajdah [prostration] and makes sajdah, Shaitan goes away from there crying. Then he says: “Shame on me. Son of Âdam was commanded to make sajdah, and he attained Paradise as he made sajdah. I, too, was commanded to make sajdah, but I became deserving of Hell as I disobeyed it.”) [Muslim]

(Beware of conceit. Conceit incited Shaitan not to make sajdah.) [I. ‘Asâkir]

Question: Why was Iblîs cursed because of his refusing to fall prostrate before Hadrat Âdam? What is the connection between Shaitan’s not making prostration to Hadrat Âdam and his being rebellious to Allah? Even if he is disobedient to Allah, does disobedience cause damnation and disbelief? Why did Allah give the order to fall prostrate for Hadrat Âdam instead of Himself?
Prostration was ordered not for Âdam ‘alaihis-salâm, but for Allah. That is, it was ordered that prostration be made for Allah in the direction of Hadrat Âdam. We, too, are making prostration for Allah in the direction of the Kaaba. We do not fall prostrate for the Kaaba itself. The angels and Iblîs were commanded that they fall prostrate for Allah in the direction of Âdam ‘alaihis-salâm. Shaitan, however, refused to make prostration by saying that this command was wrong. In other words, what caused his being cursed was not his not falling prostrate but his saying that the command of Allah was wrong.

Those who do not perform namâz, who do not fast cannot be called disbelievers (kâfir), though they are in acts of disobedience to Allah. But if they deem namâz or fast unnecessary, they become disbelievers.

Likewise, Shaitan deemed Allah’s command inappropriate and said, “I was created from fire, but he was created from soil. It is wrong for a being created from fire to accept a being created from soil as the direction for prostration.” Thus, he declined to prostrate himself and became one of those who are cursed eternally.