A stretch of sand in New Zealand was the scene of both tragedy and triumph this weekend as rescuers raced to save hundreds of stranded pilot whales after 300 others died in one of the country’s largest beaching events.

On Thursday, the New Zealand Department of Conservation discovered more than 400 whales stranded on the South Island’s Farewell Spit, more than half of them already dead. Conservation officials and the animal welfare group Project Jonah spearheaded a mass “refloating” to rescue the whales that were still alive and guide them back to the water.

But over the following days, hundreds more whales from a different pod also became stranded. More than 500 volunteers rushed to save them as well.

All told, nearly 700 whales washed up on Farewell Spit in what is now the third-largest whale stranding since data collection began in the 1800s, and the largest ever since 1985, the Department of Conservation said. Officials declared almost 350 whales dead.

This post contains images and descriptions of dead whales that may disturb some readers.

Anthony Phelps/Reuters Volunteers try to help stranded pilot whales stuck on the shores of New Zealand's Farewell Spit on Feb. 11, 2017.

Anthony Phelps/Reuters More than 500 people worked for days to help save as many of the stranded whales as they could.

The saga appeared to be over on Sunday, after the last 17 surviving whales successfully returned to the ocean and rejoined a pod swimming just offshore.

Conservation officials praised the work of the volunteers, who formed a human chain in the water at one point to prevent the whales from re-beaching themselves.

“People seem to have an emotional attachment to marine mammals,” Herb Christophers, a spokesman for the Department of Conservation, told The Associated Press. “They’ve been singing songs to them, giving them specific names, treating them as kindred spirits.”

Anthony Phelps/Reuters Volunteers form a human chain to prevent whales from stranding themselves on the beach.

Anthony Phelps/Reuters Nearly 700 whales were stranded on Farewell Spit along New Zealand's South Island.

A pod of pilot whales can number between 20 to 100 animals, according to New Zealand’s government. The animals can reach up to 60 years old.

No one knows exactly why mass beachings occur, but scientists speculate that some cetaceans’ means of communication, echolocation, may not work as well near land. Echolocation “is not well-suited to shallow, gently sloping waters, because they generally prefer high relief (steep) areas such as the edge of the continental shelf,” the Department of Conservation explains on its website.

“This would also explain why most mass strandings happen in summer, when the whales follow popular food sources inshore,” the agency writes. “Another theory points to pilot whales’ highly sociable behavior ― when one whale loses its way and strands, its pod mates may swim to its aid.”

Anthony Phelps/Reuters Volunteers at Farewell Spit worked to keep the stranded whales wet.

Anthony Phelps/Reuters Volunteers prepare to refloat stranded pilot whales.

By Monday, Farewell Spit was clear of stranded whales, though officials were still monitoring a pod swimming fairly close to shore, the Department of Conservation said.

The agency is now trying to figure out what to do with the carcasses of the dead whales. Workers spent most of Monday cutting holes in their bodies to prevent them from exploding as they decomposed, and the area was closed to the public, according to Reuters.

The bodies will eventually be moved to a non-public area of the nature reserve, the BBC reports.

Anthony Phelps/Reuters Dead whales were marked with an "x" so rescuers would know they could not be saved.