All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu 'alyhi wa sallam, is His slave and Messenger.
Scholars say that the first thing that Allaah The Almighty created was the water, then the Throne, then the Pen, and then the heavens and earth. This opinion is supported by what was narrated on the authority of Abu Ruzayn that the Prophet, sallallaahu ‘alayhi wa sallam, said that the water was created before the Throne. [Ahmad and At-Tirmithi] [At-Tirmithi authenticated]
The Prophet, sallallaahu ‘alayhi wa sallam, said that Allaah The Almighty had not created anything before He created the water. [As-Sindi]
There is no contradiction between this and what was narrated on the authority of ‘Ubaadah ibn As-Saamit that the Prophet, sallallaahu ‘alayhi wa sallam, said that the first thing that Allaah The Almighty created was the Pen, and that Allaah ordered it to write down everything that would take place until the Day of Judgment. [Ahmad and At-Tirmithi] [At-Tirmithi: authenticated]
Al-Haafith Ibn Hajar said that the Hadeeth (narration) means that the Pen was created after the water and the Throne. It was also said that the Pen was ordered to write as soon as it was created, not that it was the first to be created. Thenceforth, other creatures were created successively.
Allaah Knows best.