Wikipedia has a good entry on the tradition of the ship’s cat. While their services were mainly needed for rodent control, they provided comfort to the crew as well:
Cats have a high ability to adapt to new surroundings, and were therefore highly suitable for service on a ship. They also offered companionship and a sense of home and security to sailors who could be away from home for long periods, especially in times of war.
The page includes several photos, including this one (caption by Wikipedia):

Nice. Ship cats – useful in more than one way!
And just a reminder that there’s a chipin for the animals in Marlboro county that have been pulled by the local humane society –
http://humanesocietyofmarlborocounty.chipin.com/help-for-the-homeless-animals-in-marlboro-county-south-carolina
And not to forget about rats getting on ships. When you see a boat tied up you will see large metal squirrel guards around the lines to guard against wharf rats climbing the lines. In the older days a pregnant rat getting onboard could easily be the death of crew members from disease and damage to the stores (food).
Just like in Egypt for the plague it probably didn’t take long for them to put two and two together.
Come to think of it to this day other than traps there is no better (greener) way of controlling rats and mice. I have never seen a small family dairy barn that didn’t keep cats on hand (southern US) as a buffer to the mice.