A custom of the sea is a custom that is said to be practiced by the officers and crew of ships and boats in the open sea, as distinguished from maritime law, which is a distinct and coherent body of law that governs maritime questions and offenses.
Among these customs was the practice of cannibalism among shipwrecked survivors, by the drawing of lots to decide who would be killed and eaten so that the others might survive.  
This specific custom, which was also known as "the delicate question" or "the proper tradition of the sea", specified that in case of disaster, when there was not enough food for the survivors, corpses could be eaten. If "there were no bodies available for consumption, lots were drawn to determine who would be sacrificed to provide food for the others." As long as the lottery was fair, giving everyone an equal risk of dying to become food for the others, this was considered "entirely legal" and justified by the circumstances. "On the whole, sailors and the general public knew and accepted [this] protocol of cannibalism to survive ship disasters." 
The historian A.W. Brian Simpson observed:
If properly conducted, cannibalism was legitimated by a custom of the sea; and the popular literature, augmented by the unrecorded tales seamen told each other, ensured that there was general understanding of what had to be done on these occasions and that survivors who had followed the custom could have a certain professional pride in a job well done; there was nothing to hide. 
Referring to William Arens' widely-read book The Man-Eating Myth, he added that, since "maritime survival cannibalism, preceded by the drawing of lots and killing, was a socially accepted practice among seamen until the end of the days of sail ... it is ... not an exception but a counterexample" to Arens' thesis "that cannibalism, as a socially accepted practice, is a myth". 
The only cases when cannibalism in maritime disasters sometimes led to legal prosecution was "when the lotteries were fixed or absent altogether", in violation of the accepted custom.  Such violations were nevertheless common enough. Captains and other crew members were often unwilling to put their own lives at risk, as the rules of the custom demanded, instead choosing to sacrifice those they considered "more expendable ... (such as slaves, young boys, and passengers)" to serve as food for the other survivors. 
The case of R v Dudley and Stephens (1884 14 QBD 273 DC) is an English case which developed a crucial ruling on necessity in modern common law, at the same time ending the custom of lot drawing and cannibalism. The case dealt with four crew members of an English yacht, the Mignonette, who in 1884 were shipwrecked in a storm some 1,600 miles from the Cape of Good Hope. After a few weeks adrift in a lifeboat, the 17-year-old crew member Richard Parker fell unconscious due to a combination of hunger and drinking seawater. The others (one abstaining) decided to kill him and eat him. They were picked up four days later. The case held that necessity was not a defense for a charge of murder, and the two defendants were convicted, though their death sentence was commuted to six months' imprisonment. 
In this case, the rules of the traditional custom had not been adhered to since no lots had been drawn. However, the judges made it clear that they did not consider necessity a possible justification for murder regardless of the circumstances. So they did not consider killing anyone acceptable even if this was the sole way to ensure the survival of the others, instead "pompous[ly]" declaring that the right course of action, under the circumstances, would have been for everybody to starve to death. 
After this judgment there were no more cases of openly admitted cannibal killings on board of British or American ships. This does not necessarily mean that they no longer occurred — but the sailors had certainly learned that more discretion was now required, since the custom had effectively been declared unlawful in the Mignonette case. In the 1890s, there were two more highly suspicious cases of maritime hunger cannibalism, but the survivors asserted that the eaten had died a natural death. Nobody seemed strongly inclined to try to prove otherwise, and no juridical proceedings follows. 
In other countries, the defense of necessity to prevent starvation in case of shipwrecks proved somewhat more durable. In the 1890s, two such incidents occurred on Norwegian vessels. In one case, lots were drawn to select a victim, while in the other case, two sailors were stabbed to death and eaten because the other sailors considered them close to death anyway. In both cases, the authorities investigated but decided not to press charges, considering the acts as justified by necessity. 
In the early 17th century, seven Englishmen in the Caribbean embarked on an overnight voyage from Saint Christopher Island, but were blown out to sea and lost for 17 days. During this time, starving, they cast lots to see who would sacrifice his own life for the others. The lot fell to the man who had suggested the scheme, and he consented to his subsequent killing. His body sustained the rest until they made their way to Saint Martin. They were returned to Saint Christopher where they were put on trial for homicide. The judge pardoned them, their crime being "washed away" by "inevitable necessity".
This case's first detailed summary in high-brow British publications was in a post-1884 medical work, not in any law reports. 
After a whale rammed and sank the whaling ship Essex of Nantucket on 20 November 1820, the survivors were left floating in three small whaleboats. They eventually resorted, by common consent, to cannibalism to allow some to survive.  Of the seven crew eaten, six died of starvation and exposure; one, Owen Coffin, lost a lottery, and was shot. The captain volunteered to take Coffin's place but Coffin refused, instead accepting his lot stoically. 
In the case of the Mary, which sunk in 1736, and the Euxine, which shipwrecked in 1874, lots were ostensibly drawn to determine a victim for killing and cannibalism. However, in both cases there are doubts whether the lot drawing was fair (and whether it even happened), since the lot fell, conveniently from the viewpoint of the core crew, on an "obvious victim" – a passenger in the case of the Mary, an adolescent boy in the case of the Euxine. 
In other cases it is known that somebody was killed for survival cannibalism without a fair lottery taking place. In such cases, the victim was almost always a person of low status, such as a black slave or a teenage boy. 
In the winter of 1765/66, the American ship Peggy drifted for months after a severe storm had destroyed all its means of navigation. Having eaten all their provisions, as well as any remaining "tobacco, lamp oil, candles, and ... leather", the crew told the captain they would hold a lottery to decide who should be slaughtered to feed the others. But among themselves they had already decided to kill the one black slave on board, and after a sham lottery they "shot him through the head. One of the crew ate the victim's raw liver; some of the rest of the body was cooked, and the remainder was pickled." 
At nearly the same time, in 1766, a vessel named Tiger was shipwrecked. After provisions had run out, the sailors decided to kill the one "negro youth" on board (probably a slave) rather than drawing lots, as one of them freely reported afterwards. The dead body was then smoked to last longer. 
The Irish sailing barque Francis Spaight capsized and almost sunk in December 1836, near the coast of Canada. All provisions were lost or spoiled. Four of the fifteen survivors were teenage apprentices. Two weeks after the accident, the captain decided that "lots should be drawn between the four boys, as they had no families, and could not be considered so great a loss to their friends, as those who had wives and children depending upon them." The boys protested against this unfair decision, but in vain. The lot fell on fourteen-year-old Patrick O'Brien, who was then killed by the ship's cook. During the next days, the sailors survived by drinking his blood and eating his flesh. 
In the late nineteenth century, a British resident magistrate met a captain named Anson whose crew "had run short of provisions" while "bring[ing] a yacht from England to Australia". Accordingly, they had killed and "eaten the cabin boy". No lot drawing is mentioned but they had somehow escaped legal consequences, "probably upon some plea of self-preservation". 
Edgar Allan Poe's only novel, The Narrative of Arthur Gordon Pym of Nantucket (1838), has a minor character, Richard Parker, who is cannibalised by the shipwreck's survivors. In an eerie parallel to the actual case of the Mignonette, which happened more than 50 years later, both cannibalised people shared the exact same name.
In 1866, W.S. Gilbert wrote a song, "The Yarn of the Nancy Bell", in which the last survivor of shipwreck sings that he is the entire crew after drawing lots and eating his other shipmates.
The stories of Richard Parker (real and fictional) inspired the name of the tiger in Yann Martel's novel Life of Pi, in which cannibalism is discussed in relation to a shipwreck.
The 2019 movie Harpoon, in which three friends are stranded aboard their yacht at sea, references both the incident aboard the Mignonette and the Edgar Allen Poe story. One of the characters is also named Richard Parker.