MAE SAI, Thailand - Divers compared it to mountain climbing, but in tight, pitch-black spaces and buffeted by swirling floodwaters, towing a child.
They had to guide their charges through passages as narrow as a couple of feet, weighed down by bulky equipment. A diver in front led the way, with a boy tethered to him and another diver following behind.
Each arduous round-trip extraction took between nine and 11 hours.
Finally, on Tuesday, the "all-star" team of expert cave divers from at least six countries completed the mission once feared impossible, pulling to safety the last of the 12 young soccer players and their 25-year-old coach from the remote cave where they were marooned for more than two weeks.
"We've rescued everyone," said Narongsak Osatanakorn, the former governor of Chiang Rai province and the lead rescue official, as volunteers and journalists erupted in jubilant cheers and claps. "We achieved a mission impossible."
The Thai navy SEALs added in a Facebook post: "We are not sure if this is a miracle, a science, or what."
The disappearance of the boys and their novice monk turned soccer coach from this small town on the Thailand-Myanmar border - remarkably found alive nine days after they went missing June 23 - launched an extraordinary saga of international cooperation and ingenuity, as experts from many fields planned how to maneuver all 13 out alive.
When no clear opening could be found atop the mountain range housing the cave, having the boys swim out with the 18-strong team of British, Australian, Chinese, Thai, American and Danish divers was considered the least risky of a range of daunting options.
The dramatic three-day mission kicked off Sunday after days spent preparing the cave - and the boys. One diver said in a Facebook post that he had spent 63 hours in the cave system over the past nine days.
The effort that swelled and gained momentum after the group was found last Monday involved more than 100 other rescuers inside the cave, 1,000 members of the Thai army and almost 10,000 others who facilitated everything from rides up to the cave site to meals of fried chicken, eggs and rice and noodle soups for divers, volunteers and journalists. International experts set up rescue communications, while Thai villagers set up coffee stalls and massage stations.
The mission was also a race against the weather.
Rescuers had spent days balancing the risk of impending monsoons, which could have flooded the cave again, against the boys' readiness, weakened as they were by their ordeal. Rain fell periodically throughout the three days of extractions, but pumping efforts were so successful that the amount of time the boys spent underwater was minimized, officials said.
Tension that had gripped this small town near the site finally broke Tuesday evening as the last of the ambulances turned on their lights and sirens and raced downhill from the cave. Thai police lining the road from the entrance laughed and flashed thumbs ups at the vast numbers of news organizations from all over the world waiting for this very scene.
Onlookers cheered, "Hooyah moo pa!" - a reference to the name of the boys' soccer team, Moo Pa, or Wild Boars.
A hint of setting sun and blue skies broke through the heavy clouds behind the caves as a helicopter whirred through the sky, carrying the last boys recovered to a hospital in nearby Chiang Rai.
Thai navy SEALs and an Australian medic who had been stationed with the boys for days, preparing them for their dive, were brought out of the cave soon after.
On Sunday, officials decided they could no longer wait, saying conditions were "as perfect as they will be" for a rescue attempt. Over the next three days, the boys were brought out in groups: four on the first day, four on the second and four, plus their coach, on Tuesday.
Among those rooting for their rescue were world leaders, Facebook founder Mark Zuckerberg and billionaire inventor Elon Musk, who tasked his team of engineers with building a "kid-sized submarine" made out of rocket parts that would be able to move the young boys through the cave's narrow passageways.
Shortly after the full rescue was announced, President Donald Trump sent a congratulatory message.
"On behalf of the United States, congratulations to the Thai Navy SEALs and all on the successful rescue of the 12 boys and their coach from the treacherous cave in Thailand. Such a beautiful moment - all freed, great job!" he wrote.
Doctors attending to the eight boys who were rescued Sunday and Monday said they are generally in good health. It was an incredible result considering that the boys spent nine days incommunicado, without food, until they were found, and then waited days more before embarking on an hours-long dive that even the most skilled cave divers have described as among the most dangerous they have attempted.
A retired Thai navy SEAL died Friday after he ran out of oxygen while placing compressed-air tanks along the exit route.
"Doctors have treated the boys, and now all of them are OK and cheerful and are talking normally," said Jesada Chokedamrongsuk, permanent secretary of the Thai Ministry of Public Health. One of the boys initially had a heartbeat that was too slow, and some had low white-blood-cell counts, but they have since been stabilized. Two have been treated for minor lung infections, doctors added. They were all treated for rabies - in case there were bats in the cave - as well as tetanus, and they were given IV drips.
Doctors expect the boys to be in the hospital for about seven days, although they could be out sooner if their bloodwork comes back negative for abnormalities.
None of them have fevers, and all are able to eat normal "medical" food, Jesada said, an improvement from the watered-down porridge they were fed when they were first rescued. A nutritionist is monitoring their diet and has recommended that they eat nothing spicy or salty - despite the boys' cravings for spicy basil pork and rice and grilled pork.
By Monday evening, the boys were able to joke, laugh and have normal conversations, doctors said. So far, their families have seen them through a glass barrier.
Officials said that families of the rescued group were preparing to head to Chiang Rai, finally able to see their loved ones after weeks of agony. Among them was Umporn Sriwichai, an aunt of assistant coach Ekapol Chanthawong. She has cared for the young man since his parents died when he was 10.
"I just want to give him a hug and say I missed you," she said. "That is the first thing I will do."
This article was written by Shibani Mahtani, a reporter for The Washington Post. The Washington Post's Timothy McLaughlin and Steve Hendrix in Mae Sai and Brian Murphy in Washington contributed to this report.