A sperm whale filmed swimming among people at Western Australian beach has died after becoming stuck on a sandbar.
Wildlife officers had spent several days trying to guide the elderly whale - which was injured and severely sunburnt - back to deeper waters.
Swimmers were pictured stroking the 15m (49ft) mammal on Saturday while it was still alive, prompting experts to warn of dangers to both it and humans.
The whale's carcass will now be removed to minimise shark risks.
The largest toothed whale in the world, sperm whales are deep sea feeders and rarely spotted near shore. Authorities were alarmed to find the whale swimming dangerously close to Port Beach in Fremantle on Saturday.
"We were pretty aware very quickly that it wasn't in good condition," said Mark Cugley, a spokesman for the state's Department of Biodiversity, Conservation and Attractions.
The 30-tonne animal returned to sea but wildlife experts warned it was at risk of stranding and that interacting with it was dangerous.
The whale reappeared on Monday nearby at Rockingham, where it beached itself.
Authorities closed the beach as they tried to save it. Rescuers sprayed the animal with water to minimise its blistering and sunburn, but it was too weak to return to sea and deteriorated further before dying on Tuesday morning.
Mr Cugley said the department would now make plans to remove the carcass using a crane, and transport it to landfill.
"We will be looking at certainly doing some post-mortem or necropsy analysis as well to understand anything more we can about the death of the whale and also about this species, given it's quite unusual to have a sperm whale in this area of Perth," he said.
Individual whale strandings are not uncommon in Australia, particularly when the animals are sick, which can often cause them to become disorientated.
Sperm whales are listed as endangered in Australia. Numbers are recovering after they were hunted to near extinction in the 19th and 20th centuries.