Assalamu Alaykum I woke up 9 min before Fajr time ended and I had a wet dream. And I had to relieve myself. But then I saw that I still had left 3-4 min while relieving myself. So I didn’t rush anymore because I thought I’m gonna miss the time either way. Is my prayer still valid?

Ustadh AbdulAziz al-Haqqan
You could have put the shower in you for 1 minute and then pray before u relieved urself if that was actually possible. Here is the fatwa of Imam Ibn Haz regarding this: Question: This question concerns someone who woke up late—at the end of the time for Fajr prayer. If he were to perform a full ritual bath (ghusl), the sun would rise; but if he prayed using dry ablution (tayammum), he would catch the prayer within its time. Answer (by Imam Ibn Baz): He is required to perform ghusl, even if the time for prayer ends. The Prophet (peace be upon him) said: “Whoever oversleeps a prayer or forgets it must pray it when he remembers it. There is no expiation for it other than that.” So, the time for that prayer becomes the moment he wakes up or remembers. Therefore, when he wakes from sleep or remembers after forgetfulness, he must promptly perform ghusl and pray. There is no blame upon him, for he is excused.