Image caption Whales undoubtedly have complex brains, but are they capable of acts of revenge?

The revenge of a whale or an accidental tragedy? A dramatic retelling of the story that inspired Herman Melville's classic novel will be hitting our screens on BBC One this Sunday - but do whales really attack humans intentionally?

Sperm whales are relatively placid mammals and very few incidents in modern times suggest otherwise. They mainly feed on squid and rarely attack, apparently only when mistaking other mammals for seals or prey.

In his 1839 book about the natural history of sperm whales, Thomas Beale, a surgeon aboard a whaleship, described them as "a most timid and inoffensive animal readily endeavouring to escape from the slightest thing which bears an unusual appearance".

But Dr Richard Bevan, a zoologist and lecturer at Newcastle University, suggests that a sperm whale may remember if it was previously attacked.

"I have no doubt that an individual would remember being harpooned and might respond aggressively if it thought that it was threatened," he said.

Image caption Gregory Peck (front, second from right) portrayed Ahab in the 1956 film version of Moby Dick

"On the other hand a large vessel like a whaling boat would probably look like a very large threat, even to a full grown sperm whale, so I'd have thought it more likely to have moved away."

But 19th century literature seems to suggest otherwise, with numerous stories of sperm whales attacking ships on purpose. But were they fuelled by threat, hunger or, as in Melville's classic novel, even revenge?

In 1820, a giant sperm whale, apparently 85 feet long (the average is 50ft) attacked a whaleship named the Essex, causing her to sink. Her crew were left adrift in three whaleboats (lighter boats used in the capture of whales) thousands of miles from land.

Alone in the middle of the Pacific Ocean the men had to decide whether to head for the nearest islands, a thousand miles downwind to the west, or set out on an epic journey of almost three thousand miles to reach the South American mainland.

Fear of cannibals forced them to choose South America, but they never made it.

Of the 21 crew members aboard The Essex, just eight members of the crew were rescued after more than 80 days at sea; with an incredible tale of starvation, dehydration and unfathomable, mortal desperation to tell.

Image caption Whaling was a lucrative business in the 19th Century, driven by commodities such as whale oil

Two members of the crew wrote accounts of the failed voyage. First mate Owen Chase's account was a widely circulated story of the time, published just months after his return home. The other, written by cabin boy Thomas Nickerson 50 years later, was not published, but, remarkably, was discovered in an attic in 1960, 80 years after Nickerson's death.

Their accounts differ in places, but what is indisputable is that they both recall exactly how their supposedly "lucky" ship sank. It was stove by a giant whale.

Historic products obtained from whales Whale Oil - Used to lubricate machinery and provide illumination by burning it in lamps.

- Used to lubricate machinery and provide illumination by burning it in lamps. Spermaceti Oil - Found in the skull. Prized and highly regarded oil. Waxy and commonly used in making candles. Candles made of spermaceti were considered the best in the world, producing a bright clear flame without an excess of smoke.

- Found in the skull. Prized and highly regarded oil. Waxy and commonly used in making candles. Candles made of spermaceti were considered the best in the world, producing a bright clear flame without an excess of smoke. Baleen - A bone-like substance used in women's corsets, hairbrushes, buggy whops, collar stays and various other products. Sometimes called the 'plastic of the 1800's'.

- A bone-like substance used in women's corsets, hairbrushes, buggy whops, collar stays and various other products. Sometimes called the 'plastic of the 1800's'. Ambergris - Found in the bowels. Extremely rare and valuable, worth its weight in gold. Used as a perfume fixative, and was a profitable business for colonial exports.

Herman Melville heard this story, met with the captain of the Essex and was inspired to write his classic novel Moby Dick.

Moby Dick was actually named after a real whale, Mocha Dick, first spotted by sailors in the 19th century near the island of Mocha, near southern Chile. Whales were often given pet names by sailors, Tom and Dick were common - though there are no accounts of a Harry.

Mocha Dick was an albino whale, described by explorer Jerimiah N Reynolds as "an old bull whale of prodigious size and strength… white as wool". Legend has it that it killed 30 men and was covered in scars and punctured with spears from previous attempts to harpoon it; before eventually being slaughtered in 1838.

Sometimes described as Leviathans, sperm whales truly are creatures of mythical proportions. They have the largest teeth of any whale and live to be more than 60 years old. They can dive deeper than any other sea mammal (around 3km) in order to catch their favourite deep sea food, the elusive squid.

But it is the fact that they have the largest brains on Earth, ones that are more complex - in certain ways - than those of humans, that is perhaps most surprising. Their cerebral cortex is much more convoluted than the human cortex, and they are social creatures with strong bonds, staying in stable social groupings and keeping constant companions throughout their lifespan.

Dr Lindy Weilgart, a research associate in the department of biology at Dalhousie University in Canada, believes that in order "to remember all their complex social relationships (families, more distantly related kin, non-related group members), they require a good memory".

In fact, remembering traumatic past incidents could well have been the trigger for the whale that rammed the Essex.

"Briefly, I do believe a sperm whale is capable of the aggression necessary to attack a ship, especially a mother if her young was threatened," Dr Weilgart says.

"I know whalers in general often harpooned calves but kept them alive so as to attract the rest of the family group which came in aid of the calf."

"They then harpooned those adults", she says, a practice that was "particularly cruel".

However, Dr Bevan suggests that while "the cetaceans do have large brains… this is linked to their ability to process sound rather than being linked to what we regard as intelligence".

Whether they can feel emotions like vengeance, is in dispute. It is possible that the whale changed course underwater at the last minute and unwittingly collided with the ship.

Image caption The Whale on BBC One tells the story of the ill-fated voyage of The Essex

Dr Per Berggren, a lecturer in marine science at Newcastle University and specialist in marine mammals, believes this to be nearer the truth.

"It is perhaps more likely that the ship accidentally hit the whale and sustained a leak large enough to sink the vessel."

But what is remarkable in the case of the Essex sinking, is that the whale came back to strike a second time.

First Mate Chase recalled: "I turned around and saw him… directly ahead of us, coming down with twice his ordinary speed… with ten-fold fury and vengeance in his aspect.

"The surf flew in all directions about him with the continual violent thrashing of his tail. His head about half out of the water, and in that way he came upon us, and again struck the ship.

"The ship brought up as suddenly and violently as if she had struck a rock and trembled for a few minutes like a leaf."

Latest research shows that whales are self-aware, sentient and more intelligent than previously thought. They can feel pain and suffering and therefore potentially a level of cognitive function; it is also now thought they can even experience feelings of love.

Image caption Tilikum, a captive orca, was involved in the death of a trainer in 2010

Sperm whales do not have many predators, killer whales (orcas) are known to have attacked sperm whales and occasionally sharks; but since the early 1700s by a large the most serious predator of sperm whales has been homo sapiens.

Whaling in the 19th century was a lucrative business as whale oil became immensely valuable for lighting oil lamps and making candles and soaps. More than 900 whaleships were out to sea in the mid-1800s, hailing mainly from American ports, with an average voyage length of three or four years.

By the mid 19th century, whale numbers were depleting rapidly. But with the discovery of petroleum in Pennsylvania in 1859, the American whaling industry had almost completely disappeared by the start of World War I.

Whale hunting is now illegal in most parts of the world (though still practised by some nations such as Norway and Japan) and concerns about the welfare of whales in captivity are currently making waves in the news.

The documentary film Blackfish, about an orca in captivity at SeaWorld Orlando that was involved in several deaths, has recently caused controversy for the theme park. The documentary suggests that keeping the whales in captivity may be causing them to behave psychotically.

Acts including Willie Nelson and Barenaked Ladies have recently cancelled performances at the park in the wake of the film's release. But SeaWorld has issued a detailed rebuttal of claims in the film.

When First Mate Starbuck declares to Captain Ahab that "Moby Dick seeks thee not. It is thou, thou, that madly seekest him!" it's likely he was telling an awful and haunting truth.

Whether or not the sperm whale that attacked the whaleship Essex on the night of 20 November 1820 did so on purpose, we will never know. But the fascinating and undying rumour of his revenge certainly lives on.

The Whale will be shown on BBC One on Sunday 22nd December at 9pm.