A sperm whale that washed up on a beach in Spain died due to nearly 30 kilograms of trash that blocked its digestive system.

An autopsy on the 10-metre-long juvenile whale was performed after it was found near a lighthouse in Murcia, in the country's south, in February.

Twenty-nine kilograms of rubbish including plastic bags, sacks of raffia straw, ropes, nets and a drum were uncovered from the whale's digestive tract by the local El Valle Wildlife Recovery Centre.

The whale would have been unable to digest or excrete the rubbish, experts said, resulting in its death.

It likely died of peritonitis, an inflammation of the tissue that lines the abdomen, which is usually caused by an infection or a hole in the intestines.

About 29 kilograms of rubbish was found in the whale's digestive tract. ( Twitter: Espacios Naturales Murcia )

Sperm whales mostly feast on a diet of giant squid, and are known to dive almost 1 kilometre in search of food.

They also occasionally eat octopus, small sharks, crabs, shrimp and fish.

The local tourism department has since launched an anti-litter campaign to try to reduce the amount of garbage left in the waters of Murcia.

"The presence of plastics in seas and oceans is one of the greatest threats to the conservation of wildlife throughout the world," said Consuelo Rosauro, from the Murcian Government.

"Many animals get trapped in the trash or ingest large amounts of plastics that end up causing their death."

Plastic pollution is an issue affecting waters closer to Australia too.

Last month a diver shared video of masses of floating plastic at a popular dive spot in Bali, saying that he had "never seen anything like" it before.

And earlier this year, a volunteer underwater clean-up project at Manly Cove found an octopus clutching plastic drinking straws in its tentacles.