This is the story of Yunus a.s. He was sent as a prophet to some hundred thousand people. His people didn’t believe in him. There are two versions to why he left his people.
In the first version. He left to a mountain and stayed there invoking the curse of Allah upon the disbelievers. And after the appointed time for the punishment had passed, he went back to check his people but when he came back he found out that the people are all OK. He didn’t know that they had repented while he was taking shelter on the mountain.
In the second version, he left his people as he thought them to be incorrigible and therefore doomed.
So, as per the story he left in a ship and that ship was caught in a storm. The captain of the ship told them to throw away their belongings. They did but still the ship was swaying in the sea like before. At this time the thought that one of the passenger is responsible for this curse so they decided to cast the lots and throw that one passenger into the sea. All the three times, the name of Hazrat Yunus a.s. came up in the lot. So they threw him into the sea. Immediately he was swollen by a large fish.
The Quran mentions about him being in three layers of darkness that he was wrapped up in. Some say it was three fishes that swallowed each other one after the other. Others say that it was the darkness of the fish, darkness of the sea, and the darkness of the night. The Quran also doesn’t specify the time for which he was in the the belly of the fish, some say three days others say forty days.
It was probably forty days because when he was thrown back to the shore, he was too weak and the sun was burning his skin. So, Allah made a gourd vine grow where he was lay and he lay in the shade of those leaves. One day a gust of wind blew away the plant and Hazrat Yunus a.s. became angry, disappointed, and then sad. At that time Allah told him that you became sad when I removed a mere plant whom you neither grew nor created, how can I Allah remove all those people whom I created just because you gave up on them? HE learnt his lesson and immediately went back to his people.
This is the story that Quran mentions but there is one interesting fact
The Quran mentions that if Allah had wanted Hazrat Yunus a.s. would have been there in the belly of the fish till the day of resurrection. Probably hinting that there are some creatures within the sea that can outlive us until the day of resurrection.