Indonesian volunteers managed to save six whales beached on the northern tip of Sumatra but four died, a conservation official said on Tuesday.
The rescuers worked late into Monday night to free six of 10 massive sperm animals using ropes and patrol boats and turn them back into the waters off Aceh province.
"Some people got injured on the coral and the high tide was also an obstacle but we tried our best," said Sapto Aji Prabowo, head of the Aceh conservation agency.
"It is an important lesson for us on how to evacuate such huge animals if it happens again."
Prabowo said it was not known why the sperm whales, which among the biggest mammals on the planet, had washed up in shallow water.
"We plan to collect samples from the dead whales to determine the cause of death and for future research," he said.
Officials will bury the dead whales as soon as possible as there is a risk of gases building up and causing the carcasses to explode.
Earlier this year, authorities in New Zealand had to cut holes in hundreds of pilot whales that washed up on beaches on the South Island to keep them from bloating and exploding.
"If we leave them there to rot, that could also cause disease," said Prabowo.
Volunteers will use excavators to move and bury the animals. An adult sperm whale can grow up to 12 meters and weigh up to 57 tonnes.
Though unusual, whale beachings have been seen in other parts of Indonesia, a vast archipelago of over 17,000 islands.
In 2016, 29 pilot whales were briefly trapped in a mangrove swamp off the eastern coast of Java, but managed to free themselves or were helped back out to sea by fishermen.
Officials previously said 12 whales had been stranded in Aceh.