Rescuers cradled it in a shallow canal, their arms wrapped around its slick, shuddering body.
It could not eat and struggled to swim and breathe. Red umbrellas were opened above it to block the harsh sun.
It was a race against time to save the male pilot whale, slowly dying after it was discovered in Thailand near the Malaysian border.
A team of rescuers deployed buoys to keep the mammal from slipping into the water and drowning as veterinarians tended to it. It vomited five plastic bags during the rescue attempt.
The whale died after a five-day fight, the country's Department of Marine and Coastal Resources said, becoming the latest high-profile incident of marine life forced to live in oceans littered with human rubbish.
An autopsy revealed dozens of plastic bags jamming the whale's stomach, weighing 8kg in all, the agency wrote on Facebook.
Photos posted to social media showed so many long, black plastic bags that authorities were running out of room to maneuver in the operating room without standing on rubbish. A bundle of white plastic is shown next to innards stretching across an operating table.
Thai officials said they believe the whale mistook the floating plastic for food. Pilot whales primarily eat squid but are also known to hunt octopus, cuttlefish and small fish when squid prove elusive, the American Cetacean Society said.
Thon Thamrongnawasawat, a marine biologist and lecturer at Kasetsart University in Bangkok, told AFP that the plastic probably prevented the whale from digesting food.
"If you have 80 plastic bags in your stomach, you die," he said, adding that at least 300 marine animals, including pilot whales, sea turtles and dolphins, die annually after ingesting plastic in Thai waters.
More than five trillion pieces of rubbish - and counting - are in the world's oceans, according to a 2014 study. Of that, nearly 270,000 tonnes of large and small plastic debris are on the surface.
A study published last year found that 83 per cent of water samples from more than a dozen nations were contaminated with plastic fibres.
It was unclear whether the whale was a short-finned or long-finned pilot whale, although short-finned pilots commonly traverse the warmer waters typical of Southeast Asia. Males grow up to 6m and weigh up to three tonnes, with females topping out at 5m and 1.5 tons, according to the American Cetacean Society.
Pollution in the ocean has affected other whale species.
In April, a 10m sperm whale weighing nearly 6800kg was found dead on a Spanish beach. More than 27kg of rubbish clogged its digestive system.
And in 2016, some of the more than 30 beached sperm whales beached in Europe were found with plastic debris in their stomachs, National Geographic reported, including a large fishing net, an engine cover and shards of a plastic bucket.