The last remaining member of the Wild Boars soccer team and his coach have been pulled out of a flooded cave in Thailand, bringing an end to a near three-week ordeal that prompted a huge international rescue effort.

The twelfth boy and the coach were the last of the team to be rescued Tuesday, after a complicated three-day operation to extricate the team, who became trapped on June 23 when rising flood water cut off the exit, deep inside the cave.

In the last 18 days, what began as a local search for the missing 13 turned into a complex rescue operation, involving hundreds of experts who flew in from around the world to help.

The parents of the boys have maintained a constant vigil outside the cave since they went missing, praying for their safe return.

The drama has captivated people worldwide as cave experts grappled with the problem of how to free the young, malnourished boys, some of whom couldn’t swim, from a flooded cavern as monsoon rains threatened to raise water levels even further.

Two boys rescued Tuesday are still being treated at an on-site medical center, while two others have been transported to a nearby hospital where eight of their teammates are recuperating after being rescued Sunday and Monday.

A small number of Navy SEALs, including a doctor who stayed with the team for a week after their discovery, remain in the cave system and are expected to emerge soon.

Nineteen divers entered the cave at 10 a.m. local time Tuesday (11 p.m. Monday ET), many on their third mission in three days, with the aim of bringing everyone inside the cave out.

Tuesday’s rescue had been expected to take longer than the two previous operations, which took 11 and nine hours, according to the Facebook page of the Royal Thai Navy SEALs.

“Today is 10 July. It will be longer than previous ones,” the post says in Thai and English. “We will celebrate together finally. Hooyah!”

Rescued boys recovering in hospital

Earlier Tuesday, more details emerged about the ages and condition of the children already freed from the cave.

All eight boys rescued on Sunday and Monday are being treated in an isolation ward in a Chiang Rai hospital. Medical officials told reporters Tuesday that they’re healthy, fever-free, mentally fit and “seem to be in high spirits.”

Jedsada Chokedamrongsook, the permanent secretary of the Thai Health Ministry, said the first group of boys taken out on Sunday were aged 14 to 16. Their body temperatures were very low when they emerged, and two are suspected of having lung inflammation.

Families of the first four have been able to see their children through a glass window, Chokedamrongsook said. They were also able to talk on the phone. They’ll be allowed to enter the room if tests show the boys are free of infection.

The second group freed on Monday were aged 12 to 14. One had a very slow heartbeat but had responded well to treatment, Chokedamrongsook said. The hospital has sent test samples from the boys to a lab in Bangkok.

Authorities will likely look for signs of Histoplasmosis, also known as “cave disease,” an infection caused by breathing in spores of a fungus often found in bird and bat droppings, according to the Mayo Clinic.

They are all likely to stay in hospital for seven days due to their weakened immune systems. Thai Prime Minister Gen. Prayut Chan-ocha visited the hospital Monday, and spoke to relatives and hospital workers.

Prime minister Prayut Chan-ocha gives support to the families of the rescued boys and thanks hospital staff for taking care of the Wild Boar soccer team members being treated at the Chiang Rai Prachanookroh hospital.

Treacherous conditions

Divers involved in the rescue described treacherous conditions, with fast-moving shallow water passing through very narrow passages.

“This is the hardest mission we’ve ever done. The lower the water is getting, the stronger the current. It’s stronger now. Every step of the extraction is risky,” said Narongsuk Keasub, a diver for the Electricity Generating Authority of Thailand.

He’s one of a group of divers whose job is to transport air tanks into the tunnels for the SEAL teams. Before the final rescue, he told CNN that divers inside the cave faced a number of challenges.

“We can only see our hands (at a) short distance. Secondly, the stones are razor sharp which is dangerous for our diving, (and) thirdly the passage is very narrow,” he said.

Keasub said that the thought of their own children kept them going.

“I’m quite emotional as a father — everybody has this feeling because we feel like it’s our children who are inside the cave.”

The four boys rescued from the cave in Thailand Monday were wearing full face dive masks while they were carried out of the cave to the make shift hospital nearby, according to an eyewitness who is part of the rescue operations stationed at the entrance of the cave.

He added that the boys were also wearing dive suits while being carried on stretchers and that their masks were removed by medical staff at the makeshift hospital.

A dangerous journey

For several days, rain threatened to hamper what was already a complicated rescue mission. When it became clear the boys were likely going to have to dive out, experts were sent in to teach them how to use scuba gear.

Officials sourced full-faced oxygen masks small enough to fit the boys, to remove the chances of them falling off during the long arduous journey through the craggy tunnels.

Two days before the first four boys were rescued, officials warned that oxygen levels with in the cave had fallen to 15%.

According to the US Department of Labor’s Occupational Safety and Health Administration, the “optimal range” of oxygen needed in the air a person breathes in order to maintain normal function is between 19.5% and 23.5%.

Dangerously low levels would have put the boys at risk of hypoxia, a condition that causes altitude sickness.

Forecasts of more rain also threatened to raise water levels, further educing the amount of available air and jeopardizing efforts to get the boys out. However, a few days of relatively clear skies allowed rescuers to pump enough water out of the cave to allow the boys to walk through some sections.

During the hours-long trip out of the cave, each boy was accompanied underwater by two divers helping them navigate the dark, murky water. The most dangerous part is the first kilometer, during which the divers and boys are required to squeeze through a narrow, flooded channel.

Rescuers need to hold the boys’ oxygen tanks in front of them and swim pencil-like through submerged holes. Having completed this section, the boys are then handed over to separate, specialist rescue teams, who help assist them through the remainder of the cave, much of which they can wade through.

CNN.  Jo Shelley and Judith Vonberg contributed to this report.