All 12 boys and their coach have been rescued from a Thai cave on the third day of the operation

A military helicopter is shown in a photograph taken at night in Chiang Rai, Thailand.

Rescued schoolboys are moved from a military helicopter to an awaiting ambulance at a military airport in Chiang Rai, Thailand, July 9, 2018.

Athit Perawongmetha/Reuters

All 12 boys and their soccer coach were rescued on Tuesday from a flooded Thai cave complex where they had trapped for more than two weeks.

"The 12 Wild Boars and coach have emerged from the cave and they are safe," the Thai navy SEAL unit said on its official Facebook page.

There are still four rescue divers, including one doctor, who remained in the chamber with the boys after they were found that are yet to emerge.

The perilous mission to save the "Wild Boars" soccer team and their coach has gripped the world for days.

Officials have not been commenting on the rescue mission as it has been taking place, so it was not clear who had been brought out during the operation or what condition they were in.

The youngsters and their coach got trapped on June 23 while exploring the cave in the northern province of Chiang Rai after soccer practice, when a rainy season downpour flooded the tunnels.

British divers found the 13, hungry and huddled in darkness on a muddy bank in a partly flooded chamber several miles inside the complex, on Monday last week.

A crack team of foreign divers and Thai Navy SEALS has been guiding the boys out through nearly 2.5 miles of sometimes submerged, pitch-dark channels.

The head of the rescue operation, Narongsak Osottanakorn, said earlier on Tuesday the final stage would be "more challenging" because five people would be brought out, not four as on previous days, along with three Navy SEALs who have been staying with the boys since they were found.

Nevertheless, he said the rescuers were gaining experience every day.

"I hope today we will be faster or the same speed as yesterday," Narongsak said.

Rescuers have been pumping out flood waters but scattered monsoon rain has raised the danger of more water percolating back down through the limestone and coursing through the tunnels.

Authorities said earlier divers had to hold the boys close to bring them as they made their way out along a guide rope, and each boy had to wear an oxygen mask to enable normal breathing.

Tranquillizers and quarantine

Prime Minister Prayuth Chan-ocha, who visited the cave on Monday, said the boys had been given tranquillizers to stop them getting stressed on the way out of the cave, but he dismissed any suggestion they had been "sedated."

"If they were sedated, how would they come out?" he asked reporters.

The eight boys brought out on Sunday and Monday were in good health overall and some asked for chocolate bread for breakfast, officials said.

Two of the boys had suspected lung infections but the four boys from the first group rescued were all walking around in hospital.

Authorities have not confirmed the identity of the rescued boys and some of their parents said they had not been told who had been brought out they were not allowed to visit the hospital where the boys were taken.

Narongsak said the rescued boys had not been identified out of respect for the families whose sons were still trapped.

The boys were still being quarantined from their parents because of the risk of infection and would likely be kept in hospital for a week to undergo tests, officials said earlier on Tuesday.

Technology billionaire Elon Musk went into the cave on Monday and left the rescue team with a "kid-sized" submarine his company SpaceX had built, Thailand's interior Minister Anupong Paochinda said.

Musk said on Twitter: "Just returned from Cave 3. Mini-sub is ready if needed. It is made of rocket parts and named Wild Boar after kids' soccer team. Leaving here in case it may be useful in the future."

By John Geddie and Panu Wongcha-um/Reuters

Reporting by Panu Wongcha-um, Juarawee Kittisilpa, Patpicha Tanakasempipat, John Geddie and James Pomfret in Chiang Rai, and Aukkarapon Niyomyat, Panarat Thepgumpanat, Amy Sawitta Lefevre and Chayut Setboonsarng in Bangkok; Writing by James Pomfret; Editing by Paul Tait and Robert Birsel.