Cave diving is treacherous at any time but Tham Luang presents unique challenges.

Twelve boys, a football coach and 10 kilometres of caves. What could go wrong?

It's D-day.

Dark monsoon clouds loom over the mountains.

Thirteen foreign divers and five Thai Navy SEALs enter the cave.

Outside, a legion of medical staff stand by, waiting, hoping for the safe removal of 12 boys and their soccer coach, who are trapped four kilometres inside.

As the rescue begins, the rain starts to fall.

Two weeks earlier

It's Night's 16th birthday. He is the goalie and one of the oldest boys in the local Wild Boars football team.

After practice the group cycles to Tham Luang Nang Non — "the cave of the reclining lady". The sky is clear.

The boys have visited the cave several times before.

It's one of the longest caves in Thailand and cuts into a mountainside near the border with Myanmar.

A sign outside warns people not to enter between July and November, saying that is "flooding season".

While the boys and their 25-year-old assistant coach are inside a storm hits, flooding a stream at the entrance of the cave. They're trapped.

The youngest, Titan, is 11 years old.

Night doesn't come home. His birthday cake sits uneaten in the fridge.

Parents find bicycles, backpacks and football boots scattered at the entrance of the cave but the children aren't there.

Cave diving is perilous at the best of times but Tham Luang presents its own extreme challenges.

Only a handful of people have the skills to even find the boys in this sprawling labyrinth.

A ragtag team assembles. It's led by locals but draws on the expertise of Australians, Belgians, Brits, Americans.

They begin the task of scouring more than 10 kilometres of passageways, searching for the Wild Boars.

They stream into the mouth of the cool, dank cave, installing giant pipes to help pump out the millions of litres of water that block the rocky maze below.

French specialists roughly mapped the cave system in 1984 — this is a cross-section of the main entrance, which dwarfs the tiny figures of those who enter.

But the searchers can't travel far before the passageways become more constrained, their journey more treacherous.

The strong current means divers have to pull themselves along inch by inch with the risk of their mask being ripped off.

It's too murky to see anything or check the pressure gauge to know how much air is left.

They can only feel their way through.

Parts of the jagged passages are so narrow the divers must remove their gear to crawl through.

The French crew mapped the smallest gap at just 38 centimetres high.

The international rescue crews work in neck-deep streams to bring in supplies and set up static lines to help guide the divers.

"What we're doing, if you're not afraid now and then, you'd be dead a long time ago," diver Ben Reymenants, who was part of the rescue mission, says.

"When the alarm bells go off and the adrenaline rushes in, you know it's time to turn around."

The dives are long and require special air canisters that allow for longer periods underwater.

The faster the divers move or breathe, the quicker their air runs out.

The cave is full of dead ends.

They shuffle back through mud.

Ahead is only a brown glow.

Or darkness.

Until …

After more than a week of searching, British diver John Volanthen emerges from the water into a new passage.

Eyes stare back through the darkness.

"How many of you are there — 13? Brilliant," he says.

"We are coming, it's okay. Many people are coming."

Frail, thin, exhausted — but alive.

The assistant coach Ekapol Chanthawong is emaciated. He has sacrificed his share of what food the group had.

Two of the boys are also in a weaker condition. They don't even know how long they've huddled together on the small, dry shelf, starving in the dark.

It's been nine days.

Water, the elemental force threatening their lives, has also helped them survive.

On scraps of paper they scribble their first words to their parents.

"Mum and dad I love you, please don't worry. I am safe now. Love you all," writes 13-year-old 'Pong', or Somphong Jaiwong.

"Mum and dad I love you … if I can get out please take me to eat crispy pork," writes 15-year-old 'Nic', or Phiphat Photi.

The parents write back, many making it clear they are not angry at their sons for going into the cave.

Nor do they blame the coach for putting their children in danger.

"Take our children and yourself out with safety. We are waiting in front of the cave."

But the parents fear they could be waiting a long time. It's unclear how long it may take to get their children out, or indeed exactly how it might be done.

The pumps are running 24 hours a day but parts of the cave can't be drained.

The dry roads leading to the mountain have turned to mud. Monsoon season is here.

Rescuers fear if the rainy forecast is right and water levels rise again, the boys could drown.

The lack of oxygen inside the cave is also nearing critical levels. There's no time left to wait — they need to get them out. Now.

But children aren't meant to go cave diving. Most of the trapped boys can't even swim.

Somehow, they will need to stay calm as they wriggle through up to two kilometres of submerged passages.

Divers help lay air tanks along the evacuation route in preparation to get the 13 out.

Among them is Petty Officer First Class Saman Gunan, a former Thai Navy SEAL. He is returning from the chamber where the boys are trapped when he passes out from a lack of oxygen.

His diving partner performs CPR but is unable to revive him. The 38-year-old had volunteered his diving skills to help save the team.

D-day, Sunday July 8

The Wild Boars have been in the cave for more than two weeks.

On Facebook, the Thai Navy SEALs share their vow: "We, the Thai team and the international team, will bring the Wild Boars home."

The first four are prepared to leave.

The past week, the crack teams have been building the children's strength and coaching them for the complex mission.

Several hours after the rescue mission begins, an ambulance is seen leaving the cave site. The first boy is free.

By day's end, four boys aged between 14 and 16 are out and receiving treatment in hospital. The first phase of the operation has gone much better than expected.

Each child wears a full face mask so he can breathe through his mouth and nose. This is easier than the goggles and separate regulator used by a typical diver.

Medication, perhaps even sedation, reduces the risk of the boys panicking.

Two divers channel one child through the first 400 metre stretch of submerged passages to the section known as Pattaya Beach.

Other rescuers are positioned along the escape route.

Videos show at least one person being carried through the slippery, dangerous terrain on a stretcher.

But it remains unclear whether all of the boys were carried for the entire journey, even the underwater sections, or actively navigated parts of it.

Either way, it's a challenging two-kilometre course to Chamber Three, the rescue operations centre, where the final route to freedom begins.

Now, after a successful day one, the rescuers need 10 to 20 hours before they can attempt to repeat that miraculous feat.

But on Monday morning there's no news about what's next. The usual media briefing doesn't go ahead.

Then, official confirmation comes in the afternoon: the rescue has been underway for hours. And as evening falls, the flashing lights of an ambulance are seen on the mountain. Four more boys are free.

They're hungry and want a tasty meal, steamed rice with minced meat and holy basil.

Monday's operation takes two hours less than Sunday's. The rescuers refine the evacuation each time.

But the sky above is threatening to burst with rain and the pumps could fail at any minute.

Tuesday is the biggest rescue yet. The teams must evacuate the four remaining boys, including the youngest child, as well as the coach and the divers who remain with them in the cavern.

Official word comes late again, the rescue is on.

And then, cheers and applause erupt from the mountain as a helicopter takes off — the last boys are out.

The coach is close behind, as are the divers. A pump fails as the final few emerge.

#Hooyah lights up social media — the Thai Navy's morale-boosting cheer becomes a rallying cry around the world.

Narongsak Osatanakorn, the local Governor and head of the operation, describes the rescue as a symbol of unity among mankind.

"Everyone worked together without discrimination of race or religion as the ultimate goal was to save the youth football team."

That night the heavens open. The torrential rain that threatened the entire mission finally falls.

It's a long road to recovery for the Wild Boars.

Most of the boys lost two kilograms during their ordeal. At least two have lung infections, likely to be pneumonia.

For the first few days they can't even hug their families — doctors are worried about spreading disease.

There is also the risk of long-term mental health problems such as post-traumatic stress disorder.

But rescuers and doctors say the team survived because of their incredible resilience.

"Everyone is strong in mind and heart," Chiang Rai hospital director Chaiwetch Thanapaisal says.

But for one father, the cave has not returned his son.

Petty Officer Saman received a royally sponsored funeral rite. His father Wichai Gunan is proud of his beloved son.

"May you rest in peace. Rest well. Daddy loves you."

For his widow Waleeporn Gunan, pride provides a buttress against her sadness.

"You are the hero in my heart. You always were and you always will be."

Credits

This story is partly based on the interviews with divers, reports by ABC News journalists Anne Barker, Liam Cochrane, Stephen Smiley and Ange Lavoipierre, and additional reporting by AP and Reuters.