Mr. Kobelo had stowed away on ships three times before in search of work wherever he landed, according to his brother, Michael. He went to Angola, Senegal and then Singapore, where he spent a year as a night watchman and firefighter in a small dry dock. Though he could have faced prosecution, most countries do not bother to charge stowaways. Immigration authorities eventually sent him back to Tanzania.

To Mr. Mndolwa, who is barely literate and had never before left Africa, Mr. Kobelo’s descriptions of his time in Singapore — free hospital visits, restaurant meals, beaches where the police never shooed him away — sounded far better than his life in Cape Town. By day, the two men roamed the sidewalks near South Africa’s Table Bay, selling knockoff watches and soccer jerseys. By night, they slept in a makeshift lean-to under a bridge.

For those seeking escape, few routes are as perilous as the sea. Roughly 2,000 stowaways are caught each year hiding on ships. Hundreds of thousands more are sea migrants, whose journey involves some level of complicity from the ship’s crew. In interviews, these travelers compared the experience of stowing away at sea to hiding in the trunk of a car for an undetermined length of time, going to an unknown place across the most brutal of terrains. Temperatures are extreme. It is impossible to bring enough food or water. And if you try to flee en route, one former stowaway in Durban, South Africa, said, “the ground swallows you whole.”

To get on board, some stowaways pose as stevedores or deck cleaners. Others swim under the stern and squeeze through a space where the rudder meets the ship. Many scale the side, helped by “stowaway poles”: long bamboo sticks with toeholds and a hook. “Love boats,” which are common in ports and deliver prostitutes, drugs and alcohol to large ships, sometimes also bring uninvited passengers. After sneaking on board, they hide in hulls or shipping containers, crane cabs or tool trunks.

But concealed corners that might look inviting often turn deadly once ships set sail. Refrigerated fishing holds become cold, exhaust pipes heat up, shipping containers are sealed and fumigated. Maritime newsletters and shipping insurance reports offer a macabre accounting of the victims: “Crushed in the chain locker,” “asphyxiated by bunker fumes,” “found under a retracted anchor.” Most often, though, death comes slower. Vomiting from seasickness leads to dehydration. People pass out from exhaustion. They starve.

In May 2011, Mr. Mndolwa and Mr. Kobelo got their chance at a new life. They overheard a deckhand in port mention that the red-bottomed ship waiting dockside with no night watchman was leaving soon for England. Carrying their passports, a loaf of bread and a plastic bag filled with orange juice, the men shimmied across the ship’s mooring rope that night, crept down to the engine room, and stayed there, whisperingly still, for the next five days.