Inside the fish, Yunus called out in the darknesses. The Quran gives his words, in the meaning of the verse: «إِلَٰهَ إِلَّآ أَنتَ سُبْحَٰنَكَ إِنِّى كُنتُ مِنَ ٱلظَّٰلِمِينَ», no deity except You, glory be to You, I have been among the wrongdoers (21:87). In few words he declared Allah's oneness, glorified Him, and admitted his own fault.
Allah responded and saved him from the distress, and added, 'And thus do We save the believers' (21:88). Surah as-Saffat says that if he had not been among those who glorified Allah, he would have stayed in the fish's belly until the Day of Resurrection (37:143-144). Then Allah threw him onto an open shore while he was ill and caused a gourd vine to grow over him (37:145-146).
Surah al-Qalam adds that a favour from his Lord reached him, so he was not left on the bare shore in disgrace, and that his Lord chose him and made him among the righteous (68:49-50). In the same place Allah tells the Prophet ﷺ to be patient for the decision of his Lord and not to be like the companion of the fish when he called out in distress (68:48).
Sa'd ibn Abi Waqqas, may Allah be pleased with him, reported that the Prophet ﷺ said that the dua of Dhun-Nun, when he called from the belly of the fish, was the words of 21:87, and that no Muslim man calls upon Allah with it for anything without Allah answering him (Jami at-Tirmidhi 3505, graded sahih).