There is a universal Jewish practice of reciting Mode Ani as soon as one arises in the morning even though it is not discussed in the Gemara or codified in the Shulhan Aruch. Rather, the source of Mode Ani is Rabbi Moshe ben Machir’s Seder Hayom (Seder Birkot Hashahar), and is also mentioned by other Aharonim, including the HIDA (Kesher Gudal, §1:1). The HIDA also adds a prayer that one should recite after Mode Ani in which one asks to be in control of one’s anger and that one not anger Hashem.
Mode Ani appears in Siddur Tefilat HaHodesh, which was commonly used in Morocco, although the wording is slightly altered. Rather than “Melech Hai Vekayam”, the version in this Siddur is “Melech Rahum Vehanum”.
The Kaf Hahaim (O.H. 4:107) cites Rabbi Haim Palagi (Yafe Lalev), who says that according to the Zohar one is not allowed to learn or recite any words of Torah before washing Netilat Yadaim in the morning. As such, this may present a problem, since Mode Ani is recited immediately upon waking up. Nevertheless, the HIDA (ibid.) brings an opinion that it may be recited before one washes one’s hands since Mode Ani is not considered words of Torah and does not mention Hashem’s Name. This indeed is the universal custom.
Summary: Although not formally codified, reciting Mode Ani upon waking is a universal custom. It may be recited before one washes one’s hands.